diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs index d23f4f49c8..923b1534d5 100644 --- a/Terminal.Gui/Application/Application.Initialization.cs +++ b/Terminal.Gui/Application/Application.Initialization.cs @@ -7,7 +7,7 @@ namespace Terminal.Gui; public static partial class Application // Initialization (Init/Shutdown) { - /// Initializes a new instance of Application. + /// Initializes a new instance of a Terminal.Gui Application. must be called when the application is closing. /// Call this method once per instance (or after has been called). /// /// This function loads the right for the platform, Creates a . and diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index 5bfa5f2cc6..b929cce4ad 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -71,7 +71,7 @@ public static Key ArrangeKey /// The to prepare execution for. /// /// This method prepares the provided for running with the focus, it adds this to the list - /// of s, lays out the Subviews, focuses the first element, and draws the + /// of s, lays out the SubViews, focuses the first element, and draws the /// in the screen. This is usually followed by executing the method, and then the /// method upon termination which will undo these changes. /// diff --git a/Terminal.Gui/Application/ApplicationNavigation.cs b/Terminal.Gui/Application/ApplicationNavigation.cs index 1fe6972eae..f351b515d6 100644 --- a/Terminal.Gui/Application/ApplicationNavigation.cs +++ b/Terminal.Gui/Application/ApplicationNavigation.cs @@ -33,7 +33,7 @@ public ApplicationNavigation () } /// - /// Gets whether is in the Subview hierarchy of . + /// Gets whether is in the SubView hierarchy of . /// /// /// @@ -50,7 +50,7 @@ public static bool IsInHierarchy (View? start, View? view) return true; } - foreach (View subView in start.Subviews) + foreach (View subView in start.SubViews) { if (view == subView) { diff --git a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs index 9c95d23896..40b891c73d 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs @@ -33,7 +33,7 @@ public class AnsiEscapeSequence /// to the oldest outstanding request. /// /// - public required string Terminator { get; init; } + public required string? Terminator { get; init; } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs index 4b872ab626..3bffbbb7c7 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs @@ -12,7 +12,7 @@ public class AnsiEscapeSequenceRequest : AnsiEscapeSequence /// Invoked when the console responds with an ANSI response code that matches the /// /// - public required Action ResponseReceived { get; init; } + public required Action ResponseReceived { get; init; } /// /// Invoked if the console fails to responds to the ANSI response code diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiMouseParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiMouseParser.cs index 5ae29060bf..83c6c41817 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiMouseParser.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiMouseParser.cs @@ -17,11 +17,11 @@ public class AnsiMouseParser /// /// /// - public bool IsMouse (string cur) + public bool IsMouse (string? cur) { // Typically in this format // ESC [ < {button_code};{x_pos};{y_pos}{final_byte} - return cur.EndsWith ('M') || cur.EndsWith ('m'); + return cur!.EndsWith ('M') || cur.EndsWith ('m'); } /// @@ -30,10 +30,10 @@ public bool IsMouse (string cur) /// /// /// - public MouseEventArgs? ProcessMouseInput (string input) + public MouseEventArgs? ProcessMouseInput (string? input) { // Match mouse wheel events first - Match match = _mouseEventPattern.Match (input); + Match match = _mouseEventPattern.Match (input!); if (match.Success) { diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs index aec693de55..6b30b3d10e 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs @@ -108,7 +108,7 @@ private bool SendOrSchedule (AnsiEscapeSequenceRequest request, bool addToQueue) private void EvictStaleRequests () { - foreach (string stale in _lastSend.Where (v => IsStale (v.Value)).Select (k => k.Key)) + foreach (string? stale in _lastSend.Where (v => IsStale (v.Value)).Select (k => k.Key)) { EvictStaleRequests (stale); } @@ -123,9 +123,9 @@ private void EvictStaleRequests () /// /// /// - private bool EvictStaleRequests (string withTerminator) + private bool EvictStaleRequests (string? withTerminator) { - if (_lastSend.TryGetValue (withTerminator, out DateTime dt)) + if (_lastSend.TryGetValue (withTerminator!, out DateTime dt)) { if (IsStale (dt)) { @@ -178,7 +178,7 @@ public bool RunSchedule (bool force = false) private void Send (AnsiEscapeSequenceRequest r) { - _lastSend.AddOrUpdate (r.Terminator, _ => Now (), (_, _) => Now ()); + _lastSend.AddOrUpdate (r.Terminator!, _ => Now (), (_, _) => Now ()); _parser.ExpectResponse (r.Terminator, r.ResponseReceived, r.Abandoned, false); r.Send (); } @@ -206,7 +206,7 @@ private bool CanSend (AnsiEscapeSequenceRequest r, out ReasonCannotSend reason) private bool ShouldThrottle (AnsiEscapeSequenceRequest r) { - if (_lastSend.TryGetValue (r.Terminator, out DateTime value)) + if (_lastSend.TryGetValue (r.Terminator!, out DateTime value)) { return Now () - value < _throttle; } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseExpectation.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseExpectation.cs index 00aa1a9512..c66f111839 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseExpectation.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseExpectation.cs @@ -1,7 +1,7 @@ #nullable enable namespace Terminal.Gui; -internal record AnsiResponseExpectation (string Terminator, Action Response, Action? Abandoned) +internal record AnsiResponseExpectation (string? Terminator, Action Response, Action? Abandoned) { - public bool Matches (string cur) { return cur.EndsWith (Terminator); } + public bool Matches (string? cur) { return cur!.EndsWith (Terminator!); } } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs index 93d2bbeb9a..4c6656de85 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs @@ -6,12 +6,32 @@ namespace Terminal.Gui; internal abstract class AnsiResponseParserBase : IAnsiResponseParser { - private const char Escape = '\x1B'; + private const char ESCAPE = '\x1B'; private readonly AnsiMouseParser _mouseParser = new (); +#pragma warning disable IDE1006 // Naming Styles protected readonly AnsiKeyboardParser _keyboardParser = new (); protected object _lockExpectedResponses = new (); protected object _lockState = new (); + protected readonly IHeld _heldContent; + + /// + /// Responses we are expecting to come in. + /// + protected readonly List _expectedResponses = []; + + /// + /// Collection of responses that we . + /// + protected readonly List _lateResponses = []; + + /// + /// Responses that you want to look out for that will come in continuously e.g. mouse events. + /// Key is the terminator. + /// + protected readonly List _persistentExpectations = []; + +#pragma warning restore IDE1006 // Naming Styles /// /// Event raised when mouse events are detected - requires setting to true @@ -35,22 +55,6 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser /// public bool HandleKeyboard { get; set; } = false; - /// - /// Responses we are expecting to come in. - /// - protected readonly List _expectedResponses = []; - - /// - /// Collection of responses that we . - /// - protected readonly List _lateResponses = []; - - /// - /// Responses that you want to look out for that will come in continuously e.g. mouse events. - /// Key is the terminator. - /// - protected readonly List _persistentExpectations = []; - private AnsiResponseParserState _state = AnsiResponseParserState.Normal; /// @@ -64,8 +68,6 @@ protected set } } - protected readonly IHeld _heldContent; - /// /// When was last changed. /// @@ -74,17 +76,17 @@ protected set // These all are valid terminators on ansi responses, // see CSI in https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s // No - N or O - protected readonly HashSet _knownTerminators = new ( - [ - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - - // No - N or O - 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Z', - '^', '`', '~', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', - 'l', 'm', 'n', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' - ]); + protected readonly HashSet _knownTerminators = + [ + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + + // No - N or O + 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Z', + '^', '`', '~', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'l', 'm', 'n', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' + ]; protected AnsiResponseParserBase (IHeld heldContent) { _heldContent = heldContent; } @@ -137,7 +139,7 @@ int inputLength char currentChar = getCharAtIndex (index); object currentObj = getObjectAtIndex (index); - bool isEscape = currentChar == Escape; + bool isEscape = currentChar == ESCAPE; switch (State) { @@ -233,7 +235,7 @@ protected void TryLastMinuteSequences () { lock (_lockState) { - string cur = _heldContent.HeldToString (); + string? cur = _heldContent.HeldToString (); if (HandleKeyboard) { @@ -250,7 +252,7 @@ protected void TryLastMinuteSequences () // We have something totally unexpected, not a CSI and // still Esc+. So give last minute swallow chance - if (cur.Length >= 2 && cur [0] == Escape) + if (cur!.Length >= 2 && cur [0] == ESCAPE) { // Maybe swallow anyway if user has custom delegate bool swallow = ShouldSwallowUnexpectedResponse (); @@ -270,7 +272,7 @@ protected bool ShouldReleaseHeldContent () { lock (_lockState) { - string cur = _heldContent.HeldToString (); + string? cur = _heldContent.HeldToString (); if (HandleMouse && IsMouse (cur)) { @@ -328,7 +330,7 @@ protected bool ShouldReleaseHeldContent () // Finally if it is a valid ansi response but not one we are expect (e.g. its mouse activity) // then we can release it back to input processing stream - if (_knownTerminators.Contains (cur.Last ()) && cur.StartsWith (EscSeqUtils.CSI)) + if (_knownTerminators.Contains (cur!.Last ()) && cur!.StartsWith (EscSeqUtils.CSI)) { // We have found a terminator so bail State = AnsiResponseParserState.Normal; @@ -354,7 +356,7 @@ protected bool ShouldReleaseHeldContent () return false; // Continue accumulating } - private void RaiseMouseEvent (string cur) + private void RaiseMouseEvent (string? cur) { MouseEventArgs? ev = _mouseParser.ProcessMouseInput (cur); @@ -364,9 +366,9 @@ private void RaiseMouseEvent (string cur) } } - private bool IsMouse (string cur) { return _mouseParser.IsMouse (cur); } + private bool IsMouse (string? cur) { return _mouseParser.IsMouse (cur); } - protected void RaiseKeyboardEvent (AnsiKeyboardParserPattern pattern, string cur) + protected void RaiseKeyboardEvent (AnsiKeyboardParserPattern pattern, string? cur) { Key? k = pattern.GetKey (cur); @@ -394,7 +396,7 @@ protected void RaiseKeyboardEvent (AnsiKeyboardParserPattern pattern, string cur /// protected abstract bool ShouldSwallowUnexpectedResponse (); - private bool MatchResponse (string cur, List collection, bool invokeCallback, bool removeExpectation) + private bool MatchResponse (string? cur, List collection, bool invokeCallback, bool removeExpectation) { // Check for expected responses AnsiResponseExpectation? matchingResponse = collection.FirstOrDefault (r => r.Matches (cur)); @@ -422,7 +424,7 @@ private bool MatchResponse (string cur, List collection } /// - public void ExpectResponse (string terminator, Action response, Action? abandoned, bool persistent) + public void ExpectResponse (string? terminator, Action response, Action? abandoned, bool persistent) { lock (_lockExpectedResponses) { @@ -438,17 +440,17 @@ public void ExpectResponse (string terminator, Action response, Action? } /// - public bool IsExpecting (string terminator) + public bool IsExpecting (string? terminator) { lock (_lockExpectedResponses) { // If any of the new terminator matches any existing terminators characters it's a collision so true. - return _expectedResponses.Any (r => r.Terminator.Intersect (terminator).Any ()); + return _expectedResponses.Any (r => r.Terminator!.Intersect (terminator!).Any ()); } } /// - public void StopExpecting (string terminator, bool persistent) + public void StopExpecting (string? terminator, bool persistent) { lock (_lockExpectedResponses) { @@ -530,7 +532,7 @@ public Tuple [] Release () /// /// /// - public void ExpectResponseT (string terminator, Action>> response, Action? abandoned, bool persistent) + public void ExpectResponseT (string? terminator, Action>> response, Action? abandoned, bool persistent) { lock (_lockExpectedResponses) { @@ -562,7 +564,7 @@ internal class AnsiResponseParser () : AnsiResponseParserBase (new StringHeld () /// keystrokes 'swallowed' (i.e. not returned to input stream). /// /// - public Func UnknownResponseHandler { get; set; } = _ => false; + public Func UnknownResponseHandler { get; set; } = _ => false; public string ProcessInput (string input) { @@ -583,13 +585,13 @@ private void AppendOutput (StringBuilder output, char c) output.Append (c); } - public string Release () + public string? Release () { lock (_lockState) { TryLastMinuteSequences (); - string output = _heldContent.HeldToString (); + string? output = _heldContent.HeldToString (); ResetState (); return output; diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/GenericHeld.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/GenericHeld.cs index 8a5955da40..a898088038 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/GenericHeld.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/GenericHeld.cs @@ -11,7 +11,7 @@ internal class GenericHeld : IHeld public void ClearHeld () { held.Clear (); } - public string HeldToString () { return new (held.Select (h => h.Item1).ToArray ()); } + public string? HeldToString () { return new (held.Select (h => h.Item1).ToArray ()); } public IEnumerable HeldToObjects () { return held; } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs index f0424711b2..4663bd6bee 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs @@ -30,7 +30,7 @@ public interface IAnsiResponseParser /// that already has one. /// exists. /// - void ExpectResponse (string terminator, Action response, Action? abandoned, bool persistent); + void ExpectResponse (string? terminator, Action response, Action? abandoned, bool persistent); /// /// Returns true if there is an existing expectation (i.e. we are waiting a response @@ -38,7 +38,7 @@ public interface IAnsiResponseParser /// /// /// - bool IsExpecting (string terminator); + bool IsExpecting (string? terminator); /// /// Removes callback and expectation that we will get a response for the @@ -50,5 +50,5 @@ public interface IAnsiResponseParser /// if you want to remove a persistent /// request listener. /// - void StopExpecting (string requestTerminator, bool persistent); + void StopExpecting (string? requestTerminator, bool persistent); } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IHeld.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IHeld.cs index 1f0079dbed..ab18ef16ed 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IHeld.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IHeld.cs @@ -16,7 +16,7 @@ internal interface IHeld /// Returns string representation of the held objects /// /// - string HeldToString (); + string? HeldToString (); /// /// Returns the collection objects directly e.g. diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParser.cs index c0da8e023a..e637626533 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParser.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParser.cs @@ -20,7 +20,7 @@ public class AnsiKeyboardParser /// /// /// - public AnsiKeyboardParserPattern? IsKeyboard (string input, bool isLastMinute = false) + public AnsiKeyboardParserPattern? IsKeyboard (string? input, bool isLastMinute = false) { return _patterns.FirstOrDefault (pattern => pattern.IsLastMinute == isLastMinute && pattern.IsMatch (input)); } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParserPattern.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParserPattern.cs index 52b6526853..7ad36019c6 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParserPattern.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/AnsiKeyboardParserPattern.cs @@ -23,7 +23,7 @@ public abstract class AnsiKeyboardParserPattern /// /// /// - public abstract bool IsMatch (string input); + public abstract bool IsMatch (string? input); private readonly string _name; @@ -37,7 +37,7 @@ public abstract class AnsiKeyboardParserPattern /// /// /// - public Key? GetKey (string input) + public Key? GetKey (string? input) { Key? key = GetKeyImpl (input); Logging.Trace ($"{nameof (AnsiKeyboardParser)} interpreted {input} as {key} using {_name}"); @@ -51,5 +51,5 @@ public abstract class AnsiKeyboardParserPattern /// /// /// - protected abstract Key? GetKeyImpl (string input); + protected abstract Key? GetKeyImpl (string? input); } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs index 6fb6a6e75b..dce820c8dc 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs @@ -41,7 +41,7 @@ public class CsiKeyPattern : AnsiKeyboardParserPattern private readonly Regex _pattern; /// - public override bool IsMatch (string input) { return _pattern.IsMatch (input); } + public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); } /// /// Creates a new instance of the class. @@ -57,9 +57,9 @@ public CsiKeyPattern () /// /// /// - protected override Key? GetKeyImpl (string input) + protected override Key? GetKeyImpl (string? input) { - Match match = _pattern.Match (input); + Match match = _pattern.Match (input!); if (!match.Success) { diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/EscAsAltPattern.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/EscAsAltPattern.cs index 05fc5ebe48..829bbb88ee 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/EscAsAltPattern.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/EscAsAltPattern.cs @@ -7,13 +7,15 @@ internal class EscAsAltPattern : AnsiKeyboardParserPattern { public EscAsAltPattern () { IsLastMinute = true; } +#pragma warning disable IDE1006 // Naming Styles private static readonly Regex _pattern = new (@"^\u001b([a-zA-Z0-9_])$"); +#pragma warning restore IDE1006 // Naming Styles - public override bool IsMatch (string input) { return _pattern.IsMatch (input); } + public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); } - protected override Key? GetKeyImpl (string input) + protected override Key? GetKeyImpl (string? input) { - Match match = _pattern.Match (input); + Match match = _pattern.Match (input!); if (!match.Success) { diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/Ss3Pattern.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/Ss3Pattern.cs index 2e5847e0d1..1b85354054 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/Ss3Pattern.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/Ss3Pattern.cs @@ -9,19 +9,21 @@ namespace Terminal.Gui; /// public class Ss3Pattern : AnsiKeyboardParserPattern { +#pragma warning disable IDE1006 // Naming Styles private static readonly Regex _pattern = new (@"^\u001bO([PQRStDCAB])$"); +#pragma warning restore IDE1006 // Naming Styles /// - public override bool IsMatch (string input) { return _pattern.IsMatch (input); } + public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); } /// /// Returns the ss3 key that corresponds to the provided input escape sequence /// /// /// - protected override Key? GetKeyImpl (string input) + protected override Key? GetKeyImpl (string? input) { - Match match = _pattern.Match (input); + Match match = _pattern.Match (input!); if (!match.Success) { diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs index 376781e702..55a25d9bc0 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs @@ -10,7 +10,7 @@ internal class StringHeld : IHeld public void ClearHeld () { _held.Clear (); } - public string HeldToString () { return _held.ToString (); } + public string? HeldToString () { return _held.ToString (); } public IEnumerable HeldToObjects () { return _held.ToString ().Select (c => (object)c); } diff --git a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs index d4bd54863a..0b00165e1f 100644 --- a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs @@ -122,7 +122,7 @@ internal void IterationImpl () if (Application.Top != null) { - bool needsDrawOrLayout = AnySubviewsNeedDrawn (Application.Top); + bool needsDrawOrLayout = AnySubViewsNeedDrawn (Application.Top); bool sizeChanged = WindowSizeMonitor.Poll (); @@ -174,7 +174,7 @@ private void SetCursor () } } - private bool AnySubviewsNeedDrawn (View v) + private bool AnySubViewsNeedDrawn (View v) { if (v.NeedsDraw || v.NeedsLayout) { @@ -183,9 +183,9 @@ private bool AnySubviewsNeedDrawn (View v) return true; } - foreach (View subview in v.Subviews) + foreach (View subview in v.SubViews) { - if (AnySubviewsNeedDrawn (subview)) + if (AnySubViewsNeedDrawn (subview)) { return true; } diff --git a/Terminal.Gui/Input/InputBindings.cs b/Terminal.Gui/Input/InputBindings.cs index 3812cdfd49..de2578887b 100644 --- a/Terminal.Gui/Input/InputBindings.cs +++ b/Terminal.Gui/Input/InputBindings.cs @@ -43,10 +43,12 @@ public void Add (TEvent eventArgs, TBinding binding) throw new ArgumentException (@"Invalid newEventArgs", nameof (eventArgs)); } +#pragma warning disable CS8601 // Possible null reference assignment. if (TryGet (eventArgs, out TBinding _)) { throw new InvalidOperationException (@$"A binding for {eventArgs} exists ({binding})."); } +#pragma warning restore CS8601 // Possible null reference assignment. // IMPORTANT: Add a COPY of the eventArgs. This is needed because ConfigurationManager.Apply uses DeepMemberWiseCopy // IMPORTANT: update the memory referenced by the key, and Dictionary uses caching for performance, and thus @@ -208,6 +210,7 @@ public void Replace (TEvent oldEventArgs, TEvent newEventArgs) /// The set of commands to replace the old ones with. public void ReplaceCommands (TEvent eventArgs, params Command [] newCommands) { +#pragma warning disable CS8601 // Possible null reference assignment. if (TryGet (eventArgs, out TBinding _)) { Remove (eventArgs); @@ -217,6 +220,7 @@ public void ReplaceCommands (TEvent eventArgs, params Command [] newCommands) { Add (eventArgs, newCommands); } +#pragma warning restore CS8601 // Possible null reference assignment. } /// Removes a from the collection. diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index 34e058dab5..6eb4682c79 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -75,11 +75,6 @@ public override View HostControl } } - private void _top_Added (object sender, SuperViewChangedEventArgs e) - { - throw new NotImplementedException (); - } - /// public override void EnsureSelectedIdxIsValid () { @@ -559,7 +554,7 @@ private void AddPopupToTop () private void RemovePopupFromTop () { - if (_popup is { } && _top.Subviews.Contains (_popup)) + if (_popup is { } && _top.SubViews.Contains (_popup)) { _top?.Remove (_popup); _popup.Dispose (); diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index d872db769c..dce0e3147b 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -11,7 +11,7 @@ namespace Terminal.Gui; /// /// Each of , , and has slightly different /// behavior relative to , , keyboard input, and -/// mouse input. Each can be customized by manipulating their Subviews. +/// mouse input. Each can be customized by manipulating their SubViews. /// /// public class Adornment : View, IDesignable @@ -82,21 +82,6 @@ public Thickness Thickness #endregion Thickness #region View Overrides - - /// - /// Adornments cannot be used as sub-views (see ); setting this property will throw - /// . - /// - /// - /// While there are no real use cases for an Adornment being a subview, it is not explicitly dis-allowed to support - /// testing. E.g. in AllViewsTester. - /// - public override View? SuperView - { - get => base.SuperView!; - set => throw new InvalidOperationException (@"Adornments can not be Subviews or have SuperViews. Use Parent instead."); - } - /// /// Gets the rectangle that describes the area of the Adornment. The Location is always (0,0). /// The size is the size of the . @@ -180,7 +165,7 @@ protected override bool OnClearingViewport () protected override bool OnDrawingText () { return Thickness == Thickness.Empty; } /// - protected override bool OnDrawingSubviews () { return Thickness == Thickness.Empty; } + protected override bool OnDrawingSubViews () { return Thickness == Thickness.Empty; } /// Does nothing for Adornment diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 566559b2c9..0cb68c94f3 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -711,7 +711,7 @@ protected override bool OnDrawingContent () { Attribute focus = Parent.GetNormalColor (); - if (Parent.SuperView is { } && Parent.SuperView?.Subviews!.Count (s => s.CanFocus) > 1) + if (Parent.SuperView is { } && Parent.SuperView?.SubViews!.Count (s => s.CanFocus) > 1) { // Only use focus color if there are multiple focusable views focus = GetFocusColor (); diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index 19bf76f372..ac19770282 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -32,7 +32,7 @@ public Margin (View parent) : base (parent) // BUGBUG: We should not set HighlightStyle.Pressed here, but wherever it is actually needed // HighlightStyle |= HighlightStyle.Pressed; Highlight += Margin_Highlight; - SubviewLayout += Margin_LayoutStarted; + SubViewLayout += Margin_LayoutStarted; // Margin should not be focusable CanFocus = false; @@ -82,7 +82,7 @@ internal static bool DrawMargins (IEnumerable margins) view.NeedsDraw = false; - foreach (var subview in view.Subviews) + foreach (var subview in view.SubViews) { stack.Push (subview); } diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs index 849a29e2ab..072fc77bf3 100644 --- a/Terminal.Gui/View/Layout/Dim.cs +++ b/Terminal.Gui/View/Layout/Dim.cs @@ -96,7 +96,7 @@ public abstract record Dim : IEqualityOperators public static Dim? Absolute (int size) { return new DimAbsolute (size); } /// - /// Creates a object that automatically sizes the view to fit all the view's Content, Subviews, and/or Text. + /// Creates a object that automatically sizes the view to fit all the view's Content, SubViews, and/or Text. /// /// /// diff --git a/Terminal.Gui/View/Layout/DimAuto.cs b/Terminal.Gui/View/Layout/DimAuto.cs index 8f5716b1e9..f1f610f337 100644 --- a/Terminal.Gui/View/Layout/DimAuto.cs +++ b/Terminal.Gui/View/Layout/DimAuto.cs @@ -72,7 +72,7 @@ internal override int Calculate (int location, int superviewContentSize, View us { maxCalculatedSize = textSize; - if (us is { ContentSizeTracksViewport: false, Subviews.Count: 0 }) + if (us is { ContentSizeTracksViewport: false, InternalSubViews.Count: 0 }) { // ContentSize was explicitly set. Use `us.ContentSize` to determine size. maxCalculatedSize = dimension == Dimension.Width ? us.GetContentSize ().Width : us.GetContentSize ().Height; @@ -81,12 +81,12 @@ internal override int Calculate (int location, int superviewContentSize, View us { // TOOD: All the below is a naive implementation. It may be possible to optimize this. - List includedSubviews = us.Subviews.ToList (); + List includedSubViews = us.InternalSubViews.ToList (); // If [x] it can cause `us.ContentSize` to change. // If [ ] it doesn't need special processing for us to determine `us.ContentSize`. - // -------------------- Pos types that are dependent on `us.Subviews` + // -------------------- Pos types that are dependent on `us.SubViews` // [ ] PosAlign - Position is dependent on other views with `GroupId` AND `us.ContentSize` // [x] PosView - Position is dependent on `subview.Target` - it can cause a change in `us.ContentSize` // [x] PosCombine - Position is dependent if `Pos.Has [one of the above]` - it can cause a change in `us.ContentSize` @@ -98,11 +98,11 @@ internal override int Calculate (int location, int superviewContentSize, View us // [ ] PosPercent - Position is dependent `us.ContentSize` - Will always be 0 if there is no other content that makes the superview have a size. // [x] PosCombine - Position is dependent if `Pos.Has [one of the above]` - it can cause a change in `us.ContentSize` - // -------------------- Pos types that are not dependent on either `us.Subviews` or `us.ContentSize` + // -------------------- Pos types that are not dependent on either `us.SubViews` or `us.ContentSize` // [ ] PosAbsolute - Position is fixed. // [ ] PosFunc - Position is internally calculated. - // -------------------- Dim types that are dependent on `us.Subviews` + // -------------------- Dim types that are dependent on `us.SubViews` // [x] DimView - Dimension is dependent on `subview.Target` // [x] DimCombine - Dimension is dependent if `Dim.Has [one of the above]` - it can cause a change in `us.ContentSize` @@ -111,7 +111,7 @@ internal override int Calculate (int location, int superviewContentSize, View us // [ ] DimPercent - Dimension is dependent on `us.ContentSize` - Will always be 0 if there is no other content that makes the superview have a size. // [ ] DimCombine - Dimension is dependent if `Dim.Has [one of the above]` - // -------------------- Dim types that are not dependent on either `us.Subviews` or `us.ContentSize` + // -------------------- Dim types that are not dependent on either `us.SubViews` or `us.ContentSize` // [ ] DimAuto - Dimension is internally calculated // [ ] DimAbsolute - Dimension is fixed // [ ] DimFunc - Dimension is internally calculated @@ -128,7 +128,7 @@ internal override int Calculate (int location, int superviewContentSize, View us if (dimension == Dimension.Width) { - notDependentSubViews = includedSubviews.Where ( + notDependentSubViews = includedSubViews.Where ( v => v.Width is { } && (v.X is PosAbsolute or PosFunc || v.Width is DimAuto @@ -144,7 +144,7 @@ or DimAbsolute } else { - notDependentSubViews = includedSubviews.Where ( + notDependentSubViews = includedSubViews.Where ( v => v.Height is { } && (v.Y is PosAbsolute or PosFunc || v.Height is DimAuto @@ -197,11 +197,11 @@ or DimAbsolute if (dimension == Dimension.Width) { - centeredSubViews = us.Subviews.Where (v => v.X.Has (out _)).ToList (); + centeredSubViews = us.InternalSubViews.Where (v => v.X.Has (out _)).ToList (); } else { - centeredSubViews = us.Subviews.Where (v => v.Y.Has (out _)).ToList (); + centeredSubViews = us.InternalSubViews.Where (v => v.Y.Has (out _)).ToList (); } viewsNeedingLayout.AddRange (centeredSubViews); @@ -241,7 +241,7 @@ or DimAbsolute var maxAlign = 0; // Use Linq to get a list of distinct GroupIds from the subviews - List groupIds = includedSubviews.Select ( + List groupIds = includedSubViews.Select ( v => { return dimension switch @@ -259,7 +259,7 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => foreach (int groupId in groupIds.Where (g => g != -1)) { // PERF: If this proves a perf issue, consider caching a ref to this list in each item - List posAlignsInGroup = includedSubviews.Where (v => PosAlign.HasGroupId (v, dimension, groupId)) + List posAlignsInGroup = includedSubViews.Where (v => PosAlign.HasGroupId (v, dimension, groupId)) .Select (v => dimension == Dimension.Width ? v.X as PosAlign : v.Y as PosAlign) .ToList (); @@ -268,7 +268,7 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => continue; } - maxAlign = PosAlign.CalculateMinDimension (groupId, includedSubviews, dimension); + maxAlign = PosAlign.CalculateMinDimension (groupId, includedSubViews, dimension); } maxCalculatedSize = int.Max (maxCalculatedSize, maxAlign); @@ -282,11 +282,11 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => if (dimension == Dimension.Width) { - anchoredSubViews = includedSubviews.Where (v => v.X.Has (out _)).ToList (); + anchoredSubViews = includedSubViews.Where (v => v.X.Has (out _)).ToList (); } else { - anchoredSubViews = includedSubviews.Where (v => v.Y.Has (out _)).ToList (); + anchoredSubViews = includedSubViews.Where (v => v.Y.Has (out _)).ToList (); } viewsNeedingLayout.AddRange (anchoredSubViews); @@ -324,11 +324,11 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => if (dimension == Dimension.Width) { - posViewSubViews = includedSubviews.Where (v => v.X.Has (out _)).ToList (); + posViewSubViews = includedSubViews.Where (v => v.X.Has (out _)).ToList (); } else { - posViewSubViews = includedSubviews.Where (v => v.Y.Has (out _)).ToList (); + posViewSubViews = includedSubViews.Where (v => v.Y.Has (out _)).ToList (); } for (var i = 0; i < posViewSubViews.Count; i++) @@ -358,11 +358,11 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => if (dimension == Dimension.Width) { - dimViewSubViews = includedSubviews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); + dimViewSubViews = includedSubViews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); } else { - dimViewSubViews = includedSubviews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); + dimViewSubViews = includedSubViews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); } for (var i = 0; i < dimViewSubViews.Count; i++) @@ -391,11 +391,11 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => if (dimension == Dimension.Width) { - dimAutoSubViews = includedSubviews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); + dimAutoSubViews = includedSubViews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); } else { - dimAutoSubViews = includedSubviews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); + dimAutoSubViews = includedSubViews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); } for (var i = 0; i < dimAutoSubViews.Count; i++) @@ -423,11 +423,11 @@ Dimension.Height when v.Y.Has (out PosAlign posAlign) => //if (dimension == Dimension.Width) //{ - // DimFillSubViews = includedSubviews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); + // DimFillSubViews = includedSubViews.Where (v => v.Width is { } && v.Width.Has (out _)).ToList (); //} //else //{ - // DimFillSubViews = includedSubviews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); + // DimFillSubViews = includedSubViews.Where (v => v.Height is { } && v.Height.Has (out _)).ToList (); //} //for (var i = 0; i < DimFillSubViews.Count; i++) diff --git a/Terminal.Gui/View/Layout/DimAutoStyle.cs b/Terminal.Gui/View/Layout/DimAutoStyle.cs index 3d3ec1df61..efd2b4b33f 100644 --- a/Terminal.Gui/View/Layout/DimAutoStyle.cs +++ b/Terminal.Gui/View/Layout/DimAutoStyle.cs @@ -10,12 +10,12 @@ namespace Terminal.Gui; public enum DimAutoStyle { /// - /// The dimensions will be computed based on the View's and/or . + /// The dimensions will be computed based on the View's and/or . /// /// If is , will be used to determine the dimension. /// /// - /// Otherwise, the Subview in with the largest corresponding position plus dimension + /// Otherwise, the SubView in with the largest corresponding position plus dimension /// will determine the dimension. /// /// @@ -31,7 +31,7 @@ public enum DimAutoStyle /// will be used to determine the dimension. /// /// - /// The corresponding dimensions of and/or will be ignored. + /// The corresponding dimensions of and/or will be ignored. /// /// /// If is set, the dimension will be the maximum of the formatted text and the @@ -42,7 +42,7 @@ public enum DimAutoStyle /// /// The dimension will be computed using the largest of the view's , , and - /// corresponding dimension + /// corresponding dimension /// Auto = Content | Text, } \ No newline at end of file diff --git a/Terminal.Gui/View/Layout/LayoutEventArgs.cs b/Terminal.Gui/View/Layout/LayoutEventArgs.cs index 264122c664..200ef24614 100644 --- a/Terminal.Gui/View/Layout/LayoutEventArgs.cs +++ b/Terminal.Gui/View/Layout/LayoutEventArgs.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// Event arguments for the event. +/// Event arguments for the event. public class LayoutEventArgs : EventArgs { /// Creates a new instance of the class. diff --git a/Terminal.Gui/View/Layout/PosAlign.cs b/Terminal.Gui/View/Layout/PosAlign.cs index 1500e5a247..14e2470b0d 100644 --- a/Terminal.Gui/View/Layout/PosAlign.cs +++ b/Terminal.Gui/View/Layout/PosAlign.cs @@ -58,7 +58,7 @@ public required Aligner Aligner /// /// /// - public static int CalculateMinDimension (int groupId, IList views, Dimension dimension) + public static int CalculateMinDimension (int groupId, IReadOnlyCollection views, Dimension dimension) { int dimensionsSum = 0; foreach (var view in views) @@ -117,7 +117,7 @@ internal override int Calculate (int superviewDimension, Dim dim, View us, Dimen } else { - groupViews = us.SuperView!.Subviews.Where (v => HasGroupId (v, dimension, GroupId)).ToList (); + groupViews = us.SuperView!.SubViews.Where (v => HasGroupId (v, dimension, GroupId)).ToList (); } AlignAndUpdateGroup (GroupId, groupViews, dimension, superviewDimension); diff --git a/Terminal.Gui/View/SuperViewChangedEventArgs.cs b/Terminal.Gui/View/SuperViewChangedEventArgs.cs index 59ddc4ce6f..1090980794 100644 --- a/Terminal.Gui/View/SuperViewChangedEventArgs.cs +++ b/Terminal.Gui/View/SuperViewChangedEventArgs.cs @@ -2,7 +2,7 @@ /// /// Args for events where the of a is changed (e.g. -/// / events). +/// / events). /// public class SuperViewChangedEventArgs : EventArgs { @@ -20,7 +20,7 @@ public SuperViewChangedEventArgs (View superView, View subView) /// /// The parent. For this is the old parent (new parent now being null). For - /// it is the new parent to whom view now belongs. + /// it is the new parent to whom view now belongs. /// public View SuperView { get; } } diff --git a/Terminal.Gui/View/View.Adornments.cs b/Terminal.Gui/View/View.Adornments.cs index 7058fb0635..aa25bd24be 100644 --- a/Terminal.Gui/View/View.Adornments.cs +++ b/Terminal.Gui/View/View.Adornments.cs @@ -60,7 +60,7 @@ private void DisposeAdornments () /// /// Changing the size of an adornment (, , or ) will /// change the size of which will call to update the layout of the - /// and its . + /// and its . /// /// public Margin? Margin { get; private set; } @@ -116,7 +116,7 @@ public virtual ShadowStyle ShadowStyle /// /// Changing the size of an adornment (, , or ) will /// change the size of which will call to update the layout of the - /// and its . + /// and its . /// /// public Border? Border { get; private set; } @@ -233,7 +233,7 @@ public virtual void SetBorderStyle (LineStyle value) /// /// Changing the size of an adornment (, , or ) will /// change the size of which will call to update the layout of the - /// and its . + /// and its . /// /// public Padding? Padding { get; private set; } diff --git a/Terminal.Gui/View/View.Command.cs b/Terminal.Gui/View/View.Command.cs index 6b33782265..a273212fce 100644 --- a/Terminal.Gui/View/View.Command.cs +++ b/Terminal.Gui/View/View.Command.cs @@ -90,8 +90,8 @@ private void SetupCommands () // - bubbled up the SuperView hierarchy. if (!args.Cancel) { - // If there's an IsDefault peer view in Subviews, try it - var isDefaultView = SuperView?.Subviews.FirstOrDefault (v => v is Button { IsDefault: true }); + // If there's an IsDefault peer view in SubViews, try it + var isDefaultView = SuperView?.InternalSubViews.FirstOrDefault (v => v is Button { IsDefault: true }); if (isDefaultView != this && isDefaultView is Button { IsDefault: true } button) { diff --git a/Terminal.Gui/View/View.Content.cs b/Terminal.Gui/View/View.Content.cs index 418f123c28..a624219e58 100644 --- a/Terminal.Gui/View/View.Content.cs +++ b/Terminal.Gui/View/View.Content.cs @@ -25,7 +25,7 @@ public partial class View /// /// If not explicitly set, and the View has visible subviews, will return the /// maximum - /// position + dimension of the Subviews, supporting with the + /// position + dimension of the SubViews, supporting with the /// flag set. /// /// @@ -68,7 +68,7 @@ public void SetContentSize (Size? contentSize) /// /// If the content size was not explicitly set by , and the View has visible subviews, will return the /// maximum - /// position + dimension of the Subviews, supporting with the + /// position + dimension of the SubViews, supporting with the /// flag set. /// /// @@ -109,7 +109,7 @@ public void SetContentSize (Size? contentSize) /// disabled. /// /// - /// The behavior of will be to use position and size of the Subviews + /// The behavior of will be to use position and size of the SubViews /// to /// determine the size of the view, ignoring . /// @@ -128,7 +128,7 @@ public void SetContentSize (Size? contentSize) /// The behavior of will be to use /// to /// determine the - /// size of the view, ignoring the position and size of the Subviews. + /// size of the view, ignoring the position and size of the SubViews. /// /// /// diff --git a/Terminal.Gui/View/View.Drawing.cs b/Terminal.Gui/View/View.Drawing.cs index 11887b9df0..9d5521c025 100644 --- a/Terminal.Gui/View/View.Drawing.cs +++ b/Terminal.Gui/View/View.Drawing.cs @@ -78,11 +78,11 @@ public void Draw (DrawContext? context = null) DoClearViewport (); // ------------------------------------ - // Draw the subviews first (order matters: Subviews, Text, Content) + // Draw the subviews first (order matters: SubViews, Text, Content) if (SubViewNeedsDraw) { DoSetAttribute (); - DoDrawSubviews (context); + DoDrawSubViews (context); } // ------------------------------------ @@ -133,10 +133,10 @@ public void Draw (DrawContext? context = null) private void DoDrawBorderAndPaddingSubViews () { - if (Border?.Subviews is { } && Border.Thickness != Thickness.Empty) + if (Border?.SubViews is { } && Border.Thickness != Thickness.Empty) { // PERFORMANCE: Get the check for DrawIndicator out of this somehow. - foreach (View subview in Border.Subviews.Where (v => v.Visible || v.Id == "DrawIndicator")) + foreach (View subview in Border.SubViews.Where (v => v.Visible || v.Id == "DrawIndicator")) { if (subview.Id != "DrawIndicator") { @@ -147,19 +147,19 @@ private void DoDrawBorderAndPaddingSubViews () } Region? saved = Border?.AddFrameToClip (); - Border?.DoDrawSubviews (); + Border?.DoDrawSubViews (); SetClip (saved); } - if (Padding?.Subviews is { } && Padding.Thickness != Thickness.Empty) + if (Padding?.SubViews is { } && Padding.Thickness != Thickness.Empty) { - foreach (View subview in Padding.Subviews) + foreach (View subview in Padding.SubViews) { subview.SetNeedsDraw (); } Region? saved = Padding?.AddFrameToClip (); - Padding?.DoDrawSubviews (); + Padding?.DoDrawSubViews (); SetClip (saved); } } @@ -191,7 +191,7 @@ private void DoDrawBorderAndPadding (Region? originalClip) if (SubViewNeedsDraw) { - // A Subview may add to the LineCanvas. This ensures any Adornment LineCanvas updates happen. + // A SubView may add to the LineCanvas. This ensures any Adornment LineCanvas updates happen. Border?.SetNeedsDraw (); Padding?.SetNeedsDraw (); } @@ -525,22 +525,22 @@ private void DoDrawContent (DrawContext? context = null) #endregion DrawContent - #region DrawSubviews + #region DrawSubViews - private void DoDrawSubviews (DrawContext? context = null) + private void DoDrawSubViews (DrawContext? context = null) { - if (OnDrawingSubviews (context)) + if (OnDrawingSubViews (context)) { return; } - if (OnDrawingSubviews ()) + if (OnDrawingSubViews ()) { return; } var dev = new DrawEventArgs (Viewport, Rectangle.Empty, context); - DrawingSubviews?.Invoke (this, dev); + DrawingSubViews?.Invoke (this, dev); if (dev.Cancel) { @@ -552,44 +552,44 @@ private void DoDrawSubviews (DrawContext? context = null) return; } - DrawSubviews (context); + DrawSubViews (context); } /// - /// Called when the are to be drawn. + /// Called when the are to be drawn. /// /// The draw context to report drawn areas to, or null if not tracking. - /// to stop further drawing of . - protected virtual bool OnDrawingSubviews (DrawContext? context) { return false; } + /// to stop further drawing of . + protected virtual bool OnDrawingSubViews (DrawContext? context) { return false; } /// - /// Called when the are to be drawn. + /// Called when the are to be drawn. /// - /// to stop further drawing of . - protected virtual bool OnDrawingSubviews () { return false; } + /// to stop further drawing of . + protected virtual bool OnDrawingSubViews () { return false; } - /// Raised when the are to be drawn. + /// Raised when the are to be drawn. /// /// /// /// Set to to stop further drawing of - /// . + /// . /// - public event EventHandler? DrawingSubviews; + public event EventHandler? DrawingSubViews; /// - /// Draws the . + /// Draws the . /// /// The draw context to report drawn areas to, or null if not tracking. - public void DrawSubviews (DrawContext? context = null) + public void DrawSubViews (DrawContext? context = null) { - if (_subviews is null) + if (InternalSubViews.Count == 0) { return; } // Draw the subviews in reverse order to leverage clipping. - foreach (View view in _subviews.Where (view => view.Visible).Reverse ()) + foreach (View view in InternalSubViews.Where (view => view.Visible).Reverse ()) { // TODO: HACK - This forcing of SetNeedsDraw with SuperViewRendersLineCanvas enables auto line join to work, but is brute force. if (view.SuperViewRendersLineCanvas || view.ViewportSettings.HasFlag (ViewportSettings.Transparent)) @@ -606,7 +606,7 @@ public void DrawSubviews (DrawContext? context = null) } } - #endregion DrawSubviews + #endregion DrawSubViews #region DrawLineCanvas @@ -772,7 +772,7 @@ public bool NeedsDraw } } - /// Gets whether any Subviews need to be redrawn. + /// Gets whether any SubViews need to be redrawn. public bool SubViewNeedsDraw { get; private set; } /// Sets that the of this View needs to be redrawn. @@ -844,7 +844,7 @@ public void SetNeedsDraw (Rectangle viewPortRelativeRegion) } // There was multiple enumeration error here, so calling ToArray - probably a stop gap - foreach (View subview in Subviews.ToArray ()) + foreach (View subview in SubViews.ToArray ()) { if (subview.Frame.IntersectsWith (viewPortRelativeRegion)) { @@ -898,7 +898,7 @@ protected void ClearNeedsDraw () Padding?.ClearNeedsDraw (); } - foreach (View subview in Subviews) + foreach (View subview in SubViews) { subview.ClearNeedsDraw (); } diff --git a/Terminal.Gui/View/View.Hierarchy.cs b/Terminal.Gui/View/View.Hierarchy.cs index 5a0705adae..82749ffa1e 100644 --- a/Terminal.Gui/View/View.Hierarchy.cs +++ b/Terminal.Gui/View/View.Hierarchy.cs @@ -7,64 +7,115 @@ namespace Terminal.Gui; public partial class View // SuperView/SubView hierarchy management (SuperView, SubViews, Add, Remove, etc.) { [SuppressMessage ("Style", "IDE1006:Naming Styles", Justification = "")] - private static readonly IList _empty = new List (0).AsReadOnly (); + private static readonly IReadOnlyCollection _empty = []; - private List? _subviews; // This is null, and allocated on demand. + private readonly List? _subviews = []; - // Internally, we use InternalSubviews rather than subviews, as we do not expect us - // to make the same mistakes our users make when they poke at the Subviews. - internal IList InternalSubviews => _subviews ?? _empty; + // Internally, we use InternalSubViews rather than subviews, as we do not expect us + // to make the same mistakes our users make when they poke at the SubViews. + internal IList InternalSubViews => _subviews ?? []; - /// This returns a list of the subviews contained by this view. - /// The subviews. - public IList Subviews => _subviews?.AsReadOnly () ?? _empty; + /// Gets the list of SubViews. + /// + /// Use and to add or remove subviews. + /// + public IReadOnlyCollection SubViews => InternalSubViews?.AsReadOnly () ?? _empty; private View? _superView; - /// Returns the container for this view, or null if this view has not been added to a container. - /// The super view. - public virtual View? SuperView + /// + /// Gets this Views SuperView (the View's container), or if this view has not been added as a + /// SubView. + /// + /// + /// + public View? SuperView { get => _superView!; - set => throw new NotImplementedException (); + private set => SetSuperView (value); } - #region AddRemove + private void SetSuperView (View? value) + { + if (_superView == value) + { + return; + } + + _superView = value; + RaiseSuperViewChanged (); + } + + private void RaiseSuperViewChanged () + { + SuperViewChangedEventArgs args = new (SuperView, this); + OnSuperViewChanged (args); + + SuperViewChanged?.Invoke (this, args); + } + + /// + /// Called when the SuperView of this View has changed. + /// + /// + protected virtual void OnSuperViewChanged (SuperViewChangedEventArgs e) { } + + /// Raised when the SuperView of this View has changed. + public event EventHandler? SuperViewChanged; - /// Indicates whether the view was added to . - public bool IsAdded { get; private set; } + #region AddRemove - /// Adds a subview (child) to this view. + /// Adds a SubView (child) to this view. /// /// - /// The Views that have been added to this view can be retrieved via the property. See also - /// + /// The Views that have been added to this view can be retrieved via the property. + /// + /// + /// To check if a View has been added to this View, compare it's property to this View. /// /// - /// Subviews will be disposed when this View is disposed. In other-words, calling this method causes + /// SubViews will be disposed when this View is disposed. In other-words, calling this method causes /// the lifecycle of the subviews to be transferred to this View. /// + /// + /// Calls/Raises the / event. + /// + /// + /// The / event will be raised on the added View. + /// /// /// The view to add. /// The view that was added. + /// + /// + /// + /// + public virtual View? Add (View? view) { if (view is null) { return null; } - if (_subviews is null) + + //Debug.Assert (view.SuperView is null, $"{view} already has a SuperView: {view.SuperView}."); + if (view.SuperView is {}) { - _subviews = []; + Logging.Warning ($"{view} already has a SuperView: {view.SuperView}."); } - Debug.WriteLineIf (_subviews.Contains (view), $"WARNING: {view} has already been added to {this}."); + //Debug.Assert (!InternalSubViews.Contains (view), $"{view} has already been Added to {this}."); + if (InternalSubViews.Contains (view)) + { + Logging.Warning ($"{view} has already been Added to {this}."); + } // TileView likes to add views that were previously added and have HasFocus = true. No bueno. view.HasFocus = false; - _subviews.Add (view); - view._superView = this; + // TODO: Make this thread safe + InternalSubViews.Add (view); + view.SuperView = this; if (view is { Enabled: true, Visible: true, CanFocus: true }) { @@ -80,7 +131,9 @@ public virtual View? SuperView view.Enabled = false; } - OnAdded (new (this, view)); + // Raise event indicating a subview has been added + // We do this before Init. + RaiseSubViewAdded (view); if (IsInitialized && !view.IsInitialized) { @@ -94,15 +147,15 @@ public virtual View? SuperView return view; } - /// Adds the specified views (children) to the view. + /// Adds the specified SubView (children) to the view. /// Array of one or more views (can be optional parameter). /// /// - /// The Views that have been added to this view can be retrieved via the property. See also + /// The Views that have been added to this view can be retrieved via the property. See also /// and . /// /// - /// Subviews will be disposed when this View is disposed. In other-words, calling this method causes + /// SubViews will be disposed when this View is disposed. In other-words, calling this method causes /// the lifecycle of the subviews to be transferred to this View. /// /// @@ -119,38 +172,46 @@ public void Add (params View []? views) } } - /// Event fired when this view is added to another. - public event EventHandler? Added; - - /// Method invoked when a subview is being added to this view. - /// Event where is the subview being added. - public virtual void OnAdded (SuperViewChangedEventArgs e) + internal void RaiseSubViewAdded (View view) { - View view = e.SubView; - view.IsAdded = true; - view.Added?.Invoke (this, e); + OnSubViewAdded (view); + SubViewAdded?.Invoke (this, new (this, view)); } - /// Method invoked when a subview is being removed from this view. - /// Event args describing the subview being removed. - public virtual void OnRemoved (SuperViewChangedEventArgs e) - { - View view = e.SubView; - view.IsAdded = false; - view.Removed?.Invoke (this, e); - } + /// + /// Called when a SubView has been added to this View. + /// + /// + /// If the SubView has not been initialized, this happens before BeginInit/EndInit is called. + /// + /// + protected virtual void OnSubViewAdded (View view) { } - /// Removes a subview added via or from this View. + /// Raised when a SubView has been added to this View. + /// + /// If the SubView has not been initialized, this happens before BeginInit/EndInit is called. + /// + public event EventHandler? SubViewAdded; + + /// Removes a SubView added via or from this View. /// /// - /// Normally Subviews will be disposed when this View is disposed. Removing a Subview causes ownership of the - /// Subview's + /// Normally SubViews will be disposed when this View is disposed. Removing a SubView causes ownership of the + /// SubView's /// lifecycle to be transferred to the caller; the caller must call . /// + /// + /// Calls/Raises the / event. + /// + /// + /// The / event will be raised on the removed View. + /// /// /// /// The removed View. if the View could not be removed. /// + /// + /// "/> public virtual View? Remove (View? view) { if (view is null) @@ -158,9 +219,24 @@ public virtual void OnRemoved (SuperViewChangedEventArgs e) return null; } - if (_subviews is null) + if (InternalSubViews.Count == 0) + { + return view; + } + + if (view.SuperView is null) { - return view; + Logging.Warning ($"{view} cannot be Removed. SuperView is null."); + } + + if (view.SuperView != this) + { + Logging.Warning ($"{view} cannot be Removed. SuperView is not this ({view.SuperView}."); + } + + if (!InternalSubViews.Contains (view)) + { + Logging.Warning ($"{view} cannot be Removed. It has not been added to {this}."); } Rectangle touched = view.Frame; @@ -172,22 +248,25 @@ public virtual void OnRemoved (SuperViewChangedEventArgs e) { view.CanFocus = false; // If view had focus, this will ensure it doesn't and it stays that way } + Debug.Assert (!view.HasFocus); - _subviews.Remove (view); + InternalSubViews.Remove (view); // Clean up focus stuff _previouslyFocused = null; - if (view._superView is { } && view._superView._previouslyFocused == this) + + if (view.SuperView is { } && view.SuperView._previouslyFocused == this) { - view._superView._previouslyFocused = null; + view.SuperView._previouslyFocused = null; } - view._superView = null; + + view.SuperView = null; SetNeedsLayout (); SetNeedsDraw (); - foreach (View v in _subviews) + foreach (View v in InternalSubViews) { if (v.Frame.IntersectsWith (touched)) { @@ -202,44 +281,56 @@ public virtual void OnRemoved (SuperViewChangedEventArgs e) _previouslyFocused = null; } - OnRemoved (new (this, view)); + RaiseSubViewRemoved (view); return view; } + internal void RaiseSubViewRemoved (View view) + { + OnSubViewRemoved (view); + SubViewRemoved?.Invoke (this, new (this, view)); + } + /// - /// Removes all subviews (children) added via or from this View. + /// Called when a SubView has been removed from this View. + /// + /// + protected virtual void OnSubViewRemoved (View view) { } + + /// Raised when a SubView has been added to this View. + public event EventHandler? SubViewRemoved; + + /// + /// Removes all SubView (children) added via or from this View. /// /// /// - /// Normally Subviews will be disposed when this View is disposed. Removing a Subview causes ownership of the - /// Subview's + /// Normally SubViews will be disposed when this View is disposed. Removing a SubView causes ownership of the + /// SubView's /// lifecycle to be transferred to the caller; the caller must call on any Views that were /// added. /// /// public virtual void RemoveAll () { - if (_subviews is null) - { - return; - } - - while (_subviews.Count > 0) + while (InternalSubViews.Count > 0) { - Remove (_subviews [0]); + Remove (InternalSubViews [0]); } } - /// Event fired when this view is removed from another. +#pragma warning disable CS0067 // The event is never used + /// Raised when a SubView has been removed from this View. public event EventHandler? Removed; +#pragma warning restore CS0067 // The event is never used #endregion AddRemove - // TODO: Mark as internal. Or nuke. + // TODO: This drives a weird coupling of Application.Top and View. It's not clear why this is needed. /// Get the top superview of a given . /// The superview view. - public View? GetTopSuperView (View? view = null, View? superview = null) + internal View? GetTopSuperView (View? view = null, View? superview = null) { View? top = superview ?? Application.Top; @@ -257,7 +348,7 @@ public virtual void RemoveAll () } /// - /// Gets whether is in the Subview hierarchy of . + /// Gets whether is in the SubView hierarchy of . /// /// The View at the start of the hierarchy. /// The View to test. @@ -275,7 +366,7 @@ public static bool IsInHierarchy (View? start, View? view, bool includeAdornment return true; } - foreach (View subView in start.Subviews) + foreach (View subView in start.InternalSubViews) { if (view == subView) { @@ -320,87 +411,87 @@ public static bool IsInHierarchy (View? start, View? view, bool includeAdornment #region SubViewOrdering /// - /// Moves one position towards the end of the list. + /// Moves one position towards the end of the list. /// /// The subview to move. - public void MoveSubviewTowardsEnd (View subview) + public void MoveSubViewTowardsEnd (View subview) { - PerformActionForSubview ( + PerformActionForSubView ( subview, x => { - int idx = _subviews!.IndexOf (x); + int idx = InternalSubViews!.IndexOf (x); - if (idx + 1 < _subviews.Count) + if (idx + 1 < InternalSubViews.Count) { - _subviews.Remove (x); - _subviews.Insert (idx + 1, x); + InternalSubViews.Remove (x); + InternalSubViews.Insert (idx + 1, x); } } ); } /// - /// Moves to the end of the list. + /// Moves to the end of the list. /// /// The subview to move. - public void MoveSubviewToEnd (View subview) + public void MoveSubViewToEnd (View subview) { - PerformActionForSubview ( + PerformActionForSubView ( subview, x => { - _subviews!.Remove (x); - _subviews.Add (x); + InternalSubViews!.Remove (x); + InternalSubViews.Add (x); } ); } /// - /// Moves one position towards the start of the list. + /// Moves one position towards the start of the list. /// /// The subview to move. - public void MoveSubviewTowardsStart (View subview) + public void MoveSubViewTowardsStart (View subview) { - PerformActionForSubview ( + PerformActionForSubView ( subview, x => { - int idx = _subviews!.IndexOf (x); + int idx = InternalSubViews!.IndexOf (x); if (idx > 0) { - _subviews.Remove (x); - _subviews.Insert (idx - 1, x); + InternalSubViews.Remove (x); + InternalSubViews.Insert (idx - 1, x); } } ); } /// - /// Moves to the start of the list. + /// Moves to the start of the list. /// /// The subview to move. - public void MoveSubviewToStart (View subview) + public void MoveSubViewToStart (View subview) { - PerformActionForSubview ( + PerformActionForSubView ( subview, x => { - _subviews!.Remove (x); - _subviews.Insert (0, subview); + InternalSubViews!.Remove (x); + InternalSubViews.Insert (0, subview); } ); } /// - /// Internal API that runs on a subview if it is part of the list. + /// Internal API that runs on a subview if it is part of the list. /// /// /// - private void PerformActionForSubview (View subview, Action action) + private void PerformActionForSubView (View subview, Action action) { - if (_subviews!.Contains (subview)) + if (InternalSubViews.Contains (subview)) { action (subview); } diff --git a/Terminal.Gui/View/View.Keyboard.cs b/Terminal.Gui/View/View.Keyboard.cs index cc21f6203c..a47b333a1f 100644 --- a/Terminal.Gui/View/View.Keyboard.cs +++ b/Terminal.Gui/View/View.Keyboard.cs @@ -562,12 +562,12 @@ private static bool InvokeCommandsBoundToKeyOnAdornment (Adornment adornment, Ke return true; } - if (adornment?.Subviews is null) + if (adornment?.InternalSubViews is null) { return false; } - foreach (View subview in adornment.Subviews) + foreach (View subview in adornment.InternalSubViews) { bool? subViewHandled = subview.InvokeCommands (key); @@ -604,7 +604,7 @@ internal bool InvokeCommandsBoundToHotKey (Key hotKey, ref bool? handled) } // Now, process any HotKey bindings in the subviews - foreach (View subview in Subviews) + foreach (View subview in InternalSubViews) { if (subview == Focused) { diff --git a/Terminal.Gui/View/View.Layout.cs b/Terminal.Gui/View/View.Layout.cs index 67c604319a..5ae60b8ed6 100644 --- a/Terminal.Gui/View/View.Layout.cs +++ b/Terminal.Gui/View/View.Layout.cs @@ -416,7 +416,7 @@ public bool Layout (Size contentSize) { if (SetRelativeLayout (contentSize)) { - LayoutSubviews (); + LayoutSubViews (); // Debug.Assert(!NeedsLayout); return true; @@ -475,7 +475,7 @@ public bool SetRelativeLayout (Size superviewContentSize) CheckDimAuto (); - // TODO: Should move to View.LayoutSubviews? + // TODO: Should move to View.LayoutSubViews? SetTextFormatterSize (); int newX, newW, newY, newH; @@ -594,9 +594,9 @@ public bool SetRelativeLayout (Size superviewContentSize) /// The position and dimensions of the view are indeterminate until the view has been initialized. Therefore, the /// behavior of this method is indeterminate if is . /// - /// Raises the event before it returns. + /// Raises the event before it returns. /// - internal void LayoutSubviews () + internal void LayoutSubViews () { if (!NeedsLayout) { @@ -607,23 +607,23 @@ internal void LayoutSubviews () Size contentSize = GetContentSize (); - OnSubviewLayout (new (contentSize)); - SubviewLayout?.Invoke (this, new (contentSize)); + OnSubViewLayout (new (contentSize)); + SubViewLayout?.Invoke (this, new (contentSize)); // The Adornments already have their Frame's set by SetRelativeLayout so we call LayoutSubViews vs. Layout here. - if (Margin is { Subviews.Count: > 0 }) + if (Margin is { SubViews.Count: > 0 }) { - Margin.LayoutSubviews (); + Margin.LayoutSubViews (); } - if (Border is { Subviews.Count: > 0 }) + if (Border is { SubViews.Count: > 0 }) { - Border.LayoutSubviews (); + Border.LayoutSubViews (); } - if (Padding is { Subviews.Count: > 0 }) + if (Padding is { SubViews.Count: > 0 }) { - Padding.LayoutSubviews (); + Padding.LayoutSubViews (); } // Sort out the dependencies of the X, Y, Width, Height properties @@ -669,44 +669,44 @@ internal void LayoutSubviews () NeedsLayout = layoutStillNeeded; - OnSubviewsLaidOut (new (contentSize)); - SubviewsLaidOut?.Invoke (this, new (contentSize)); + OnSubViewsLaidOut (new (contentSize)); + SubViewsLaidOut?.Invoke (this, new (contentSize)); } /// - /// Called from before any subviews + /// Called from before any subviews /// have been laid out. /// /// /// Override to perform tasks when the layout is changing. /// - protected virtual void OnSubviewLayout (LayoutEventArgs args) { } + protected virtual void OnSubViewLayout (LayoutEventArgs args) { } /// - /// Raised by before any subviews + /// Raised by before any subviews /// have been laid out. /// /// /// Subscribe to this event to perform tasks when the layout is changing. /// - public event EventHandler? SubviewLayout; + public event EventHandler? SubViewLayout; /// - /// Called from after all sub-views + /// Called from after all sub-views /// have been laid out. /// /// /// Override to perform tasks after the has been resized or the layout has /// otherwise changed. /// - protected virtual void OnSubviewsLaidOut (LayoutEventArgs args) { } + protected virtual void OnSubViewsLaidOut (LayoutEventArgs args) { } /// Raised after all sub-views have been laid out. /// /// Subscribe to this event to perform tasks after the has been resized or the layout has /// otherwise changed. /// - public event EventHandler? SubviewsLaidOut; + public event EventHandler? SubViewsLaidOut; #endregion Core Layout API @@ -743,23 +743,23 @@ public void SetNeedsLayout () { NeedsLayout = true; - if (Margin is { Subviews.Count: > 0 }) + if (Margin is { SubViews.Count: > 0 }) { Margin.SetNeedsLayout (); } - if (Border is { Subviews.Count: > 0 }) + if (Border is { SubViews.Count: > 0 }) { Border.SetNeedsLayout (); } - if (Padding is { Subviews.Count: > 0 }) + if (Padding is { SubViews.Count: > 0 }) { Padding.SetNeedsLayout (); } // Use a stack to avoid recursion - Stack stack = new (Subviews); + Stack stack = new (SubViews); while (stack.Count > 0) { @@ -769,22 +769,22 @@ public void SetNeedsLayout () { current.NeedsLayout = true; - if (current.Margin is { Subviews.Count: > 0 }) + if (current.Margin is { SubViews.Count: > 0 }) { current.Margin.SetNeedsLayout (); } - if (current.Border is { Subviews.Count: > 0 }) + if (current.Border is { SubViews.Count: > 0 }) { current.Border.SetNeedsLayout (); } - if (current.Padding is { Subviews.Count: > 0 }) + if (current.Padding is { SubViews.Count: > 0 }) { current.Padding.SetNeedsLayout (); } - foreach (View subview in current.Subviews) + foreach (View subview in current.SubViews) { stack.Push (subview); } @@ -833,7 +833,7 @@ public void SetNeedsLayout () /// internal void CollectAll (View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges) { - foreach (View? v in from.InternalSubviews) + foreach (View? v in from.InternalSubViews) { nNodes.Add (v); CollectPos (v.X, v, ref nNodes, ref nEdges); @@ -1035,7 +1035,7 @@ private Size GetContainerSize () /// The new y location that will ensure will be fully visible. /// /// Either (if does not have a Super View) or - /// 's SuperView. This can be used to ensure LayoutSubviews is called on the correct View. + /// 's SuperView. This can be used to ensure LayoutSubViews is called on the correct View. /// internal static View? GetLocationEnsuringFullVisibility ( View viewToMove, @@ -1184,7 +1184,7 @@ private Pos VerifyIsInitialized (Pos pos, string member) /// Gets or sets whether validation of and occurs. /// /// Setting this to will enable validation of , , - /// , and during set operations and in . If invalid + /// , and during set operations and in . If invalid /// settings are discovered exceptions will be thrown indicating the error. This will impose a performance penalty and /// thus should only be used for debugging. /// @@ -1207,7 +1207,7 @@ private void CheckDimAuto () var heightAuto = Height as DimAuto; // Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions. - foreach (View view in Subviews) + foreach (View view in SubViews) { if (widthAuto is { } && widthAuto.Style.FastHasFlags (DimAutoStyle.Content) && ContentSizeTracksViewport) { diff --git a/Terminal.Gui/View/View.Mouse.cs b/Terminal.Gui/View/View.Mouse.cs index bdce9b5e29..b0f802af8e 100644 --- a/Terminal.Gui/View/View.Mouse.cs +++ b/Terminal.Gui/View/View.Mouse.cs @@ -113,7 +113,7 @@ private void SetupMouse () } /// - /// Called when the mouse moves over the View's and no other non-Subview occludes it. + /// Called when the mouse moves over the View's and no other non-SubView occludes it. /// will /// be raised when the mouse is no longer over the . /// @@ -808,13 +808,13 @@ internal bool SetPressedHighlight (HighlightStyle newHighlightStyle) View? subview = null; - for (int i = start.InternalSubviews.Count - 1; i >= 0; i--) + for (int i = start.InternalSubViews.Count - 1; i >= 0; i--) { - if (start.InternalSubviews [i].Visible - && start.InternalSubviews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)) - && (!ignoreTransparent || !start.InternalSubviews [i].ViewportSettings.HasFlag (ViewportSettings.TransparentMouse))) + if (start.InternalSubViews [i].Visible + && start.InternalSubViews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)) + && (!ignoreTransparent || !start.InternalSubViews [i].ViewportSettings.HasFlag (ViewportSettings.TransparentMouse))) { - subview = start.InternalSubviews [i]; + subview = start.InternalSubViews [i]; currentLocation.X = startOffsetX + start.Viewport.X; currentLocation.Y = startOffsetY + start.Viewport.Y; diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index 6799edb9d1..7cce949d49 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -265,7 +265,7 @@ public bool CanFocus public event EventHandler? CanFocusChanged; /// - /// Focuses the deepest focusable Subview if one exists. If there are no focusable Subviews then the focus is set to + /// Focuses the deepest focusable SubView if one exists. If there are no focusable SubViews then the focus is set to /// the view itself. /// /// @@ -283,12 +283,12 @@ public bool FocusDeepest (NavigationDirection direction, TabBehavior? behavior) return SetFocus (); } - /// Gets the currently focused Subview or Adornment of this view, or if nothing is focused. + /// Gets the currently focused SubView or Adornment of this view, or if nothing is focused. public View? Focused { get { - View? focused = Subviews.FirstOrDefault (v => v.HasFocus); + View? focused = SubViews.FirstOrDefault (v => v.HasFocus); if (focused is { }) { @@ -319,9 +319,9 @@ public View? Focused public bool IsCurrentTop => Application.Top == this; /// - /// Returns the most focused Subview down the subview-hierarchy. + /// Returns the most focused SubView down the subview-hierarchy. /// - /// The most focused Subview, or if no Subview is focused. + /// The most focused SubView, or if no SubView is focused. public View? MostFocused { get @@ -589,7 +589,7 @@ public bool SetFocus () if (Arrangement.HasFlag (ViewArrangement.Overlapped)) { - SuperView?.MoveSubviewToEnd (this); + SuperView?.MoveSubViewToEnd (this); } // Focus work is done. Notify. @@ -902,39 +902,39 @@ protected virtual void OnHasFocusChanged (bool newHasFocus, View? previousFocuse /// internal View [] GetFocusChain (NavigationDirection direction, TabBehavior? behavior) { - IEnumerable? filteredSubviews; + IEnumerable? filteredSubViews; if (behavior.HasValue) { - filteredSubviews = _subviews?.Where (v => v.TabStop == behavior && v is { CanFocus: true, Visible: true, Enabled: true }); + filteredSubViews = InternalSubViews?.Where (v => v.TabStop == behavior && v is { CanFocus: true, Visible: true, Enabled: true }); } else { - filteredSubviews = _subviews?.Where (v => v is { CanFocus: true, Visible: true, Enabled: true }); + filteredSubViews = InternalSubViews?.Where (v => v is { CanFocus: true, Visible: true, Enabled: true }); } // How about in Adornments? if (Padding is { CanFocus: true, Visible: true, Enabled: true } && Padding.TabStop == behavior) { - filteredSubviews = filteredSubviews?.Append (Padding); + filteredSubViews = filteredSubViews?.Append (Padding); } if (Border is { CanFocus: true, Visible: true, Enabled: true } && Border.TabStop == behavior) { - filteredSubviews = filteredSubviews?.Append (Border); + filteredSubViews = filteredSubViews?.Append (Border); } if (Margin is { CanFocus: true, Visible: true, Enabled: true } && Margin.TabStop == behavior) { - filteredSubviews = filteredSubviews?.Append (Margin); + filteredSubViews = filteredSubViews?.Append (Margin); } if (direction == NavigationDirection.Backward) { - filteredSubviews = filteredSubviews?.Reverse (); + filteredSubViews = filteredSubViews?.Reverse (); } - return filteredSubviews?.ToArray () ?? Array.Empty (); + return filteredSubViews?.ToArray () ?? Array.Empty (); } private TabBehavior? _tabStop; diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index bf4fc0d8cb..45f227cf7d 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -81,9 +81,9 @@ protected virtual void Dispose (bool disposing) DisposeAdornments (); DisposeScrollBars (); - for (int i = InternalSubviews.Count - 1; i >= 0; i--) + for (int i = InternalSubViews.Count - 1; i >= 0; i--) { - View subview = InternalSubviews [i]; + View subview = InternalSubViews [i]; Remove (subview); subview.Dispose (); } @@ -98,7 +98,7 @@ protected virtual void Dispose (bool disposing) _disposedValue = true; } - Debug.Assert (InternalSubviews.Count == 0); + Debug.Assert (InternalSubViews.Count == 0); } #region Constructors and Initialization @@ -196,9 +196,9 @@ public virtual void BeginInit () BeginInitAdornments (); - if (_subviews?.Count > 0) + if (InternalSubViews?.Count > 0) { - foreach (View view in _subviews) + foreach (View view in InternalSubViews) { if (!view.IsInitialized) { @@ -213,7 +213,7 @@ public virtual void BeginInit () /// Signals the View that initialization is ending. See . /// - /// Initializes all Subviews and Invokes the event. + /// Initializes all SubViews and Invokes the event. /// public virtual void EndInit () { @@ -232,14 +232,11 @@ public virtual void EndInit () UpdateTextDirection (TextDirection); UpdateTextFormatterText (); - if (_subviews is { }) + foreach (View view in InternalSubViews) { - foreach (View view in _subviews) + if (!view.IsInitialized) { - if (!view.IsInitialized) - { - view.EndInit (); - } + view.EndInit (); } } @@ -295,12 +292,7 @@ public bool Enabled Border.Enabled = _enabled; } - if (_subviews is null) - { - return; - } - - foreach (View view in _subviews) + foreach (View view in InternalSubViews) { view.Enabled = Enabled; } diff --git a/Terminal.Gui/View/ViewArrangement.cs b/Terminal.Gui/View/ViewArrangement.cs index b4843f7dd5..921fe1af9c 100644 --- a/Terminal.Gui/View/ViewArrangement.cs +++ b/Terminal.Gui/View/ViewArrangement.cs @@ -62,7 +62,7 @@ public enum ViewArrangement Resizable = LeftResizable | RightResizable | TopResizable | BottomResizable, /// - /// The view overlaps other views (the order of dicates the Z-order). If this flag is not + /// The view overlaps other views (the order of dicates the Z-order). If this flag is not /// set the view will operate in tiled mode. /// /// When set, Tab and Shift-Tab will be constrained to the subviews of the view (normally, they will navigate to diff --git a/Terminal.Gui/View/ViewportSettings.cs b/Terminal.Gui/View/ViewportSettings.cs index bedc9a43ca..38ab43f810 100644 --- a/Terminal.Gui/View/ViewportSettings.cs +++ b/Terminal.Gui/View/ViewportSettings.cs @@ -142,9 +142,9 @@ public enum ViewportSettings /// /// If set the View will be transparent: The will not be cleared when the View is drawn and the clip region - /// will be set to clip the View's and . + /// will be set to clip the View's and . /// - /// Only the topmost View in a Subview Hierarchy can be transparent. Any subviews of the topmost transparent view + /// Only the topmost View in a SubView Hierarchy can be transparent. Any subviews of the topmost transparent view /// will have indeterminate draw behavior. /// /// @@ -154,7 +154,7 @@ public enum ViewportSettings Transparent = 0b_0001_0000_0000, /// - /// If set the View will be transparent to mouse events: Any mouse event that occurs over the View (and it's Subviews) will be passed to the + /// If set the View will be transparent to mouse events: Any mouse event that occurs over the View (and it's SubViews) will be passed to the /// Views below it. /// /// Combine this with to get a view that is both visually transparent and transparent to the mouse. diff --git a/Terminal.Gui/Views/Bar.cs b/Terminal.Gui/Views/Bar.cs index d5b72c1857..0fe01a5245 100644 --- a/Terminal.Gui/Views/Bar.cs +++ b/Terminal.Gui/Views/Bar.cs @@ -144,12 +144,12 @@ public AlignmentModes AlignmentModes } // TODO: Move this to View - /// Inserts a in the specified index of . + /// Inserts a in the specified index of . /// The zero-based index at which item should be inserted. /// The item to insert. public void AddShortcutAt (int index, Shortcut item) { - List savedSubViewList = Subviews.ToList (); + List savedSubViewList = SubViews.ToList (); int count = savedSubViewList.Count; RemoveAll (); @@ -172,18 +172,18 @@ public void AddShortcutAt (int index, Shortcut item) // TODO: Move this to View - /// Removes a at specified index of . + /// Removes a at specified index of . /// The zero-based index of the item to remove. /// The removed. public Shortcut? RemoveShortcut (int index) { View? toRemove = null; - for (var i = 0; i < Subviews.Count; i++) + for (var i = 0; i < SubViews.Count; i++) { if (i == index) { - toRemove = Subviews [i]; + toRemove = SubViews.ElementAt (i); } } @@ -198,7 +198,7 @@ public void AddShortcutAt (int index, Shortcut item) } /// - protected override void OnSubviewLayout (LayoutEventArgs args) + protected override void OnSubViewLayout (LayoutEventArgs args) { LayoutBarItems (args.OldContentSize); } @@ -210,9 +210,9 @@ private void LayoutBarItems (Size contentSize) switch (Orientation) { case Orientation.Horizontal: - for (var index = 0; index < Subviews.Count; index++) + for (var index = 0; index < SubViews.Count; index++) { - View barItem = Subviews [index]; + View barItem = SubViews.ElementAt (index); barItem.ColorScheme = ColorScheme; barItem.X = Pos.Align (Alignment.Start, AlignmentModes); @@ -227,7 +227,7 @@ private void LayoutBarItems (Size contentSize) var minKeyWidth = 0; - List shortcuts = Subviews.Where (s => s is Shortcut && s.Visible).Cast ().ToList (); + List shortcuts = SubViews.Where (s => s is Shortcut && s.Visible).Cast ().ToList (); foreach (Shortcut shortcut in shortcuts) { @@ -235,11 +235,11 @@ private void LayoutBarItems (Size contentSize) minKeyWidth = int.Max (minKeyWidth, shortcut.KeyView.Text.GetColumns ()); } - var _maxBarItemWidth = 0; + var maxBarItemWidth = 0; - for (var index = 0; index < Subviews.Count; index++) + for (var index = 0; index < SubViews.Count; index++) { - View barItem = Subviews [index]; + View barItem = SubViews.ElementAt (index); barItem.ColorScheme = ColorScheme; @@ -255,7 +255,7 @@ private void LayoutBarItems (Size contentSize) scBarItem.MinimumKeyTextSize = minKeyWidth; scBarItem.Width = scBarItem.GetWidthDimAuto (); barItem.Layout (Application.Screen.Size); - _maxBarItemWidth = Math.Max (_maxBarItemWidth, barItem.Frame.Width); + maxBarItemWidth = Math.Max (maxBarItemWidth, barItem.Frame.Width); } if (prevBarItem == null) @@ -274,17 +274,17 @@ private void LayoutBarItems (Size contentSize) } - foreach (var subView in Subviews) + foreach (var subView in SubViews) { if (subView is not Line) { - subView.Width = Dim.Auto (DimAutoStyle.Auto, minimumContentDim: _maxBarItemWidth); + subView.Width = Dim.Auto (DimAutoStyle.Auto, minimumContentDim: maxBarItemWidth); } } } else { - foreach (var subView in Subviews) + foreach (var subView in SubViews) { if (subView is not Line) { diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 7b30e09cfb..6def5670da 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -57,14 +57,14 @@ public ComboBox () Initialized += (s, e) => ProcessLayout (); // On resize - SubviewsLaidOut += (sender, a) => ProcessLayout (); + SubViewsLaidOut += (sender, a) => ProcessLayout (); - Added += (s, e) => + SuperViewChanged += (s, e) => { // Determine if this view is hosted inside a dialog and is the only control for (View view = SuperView; view != null; view = view.SuperView) { - if (view is Dialog && SuperView is { } && SuperView.Subviews.Count == 1 && SuperView.Subviews [0] == this) + if (view is Dialog && SuperView is { } && SuperView.SubViews.Count == 1 && SuperView.SubViews.ElementAt (0) == this) { _autoHide = false; @@ -199,7 +199,7 @@ public IListDataSource Source _source = value; // Only need to refresh list if its been added to a container view - if (SuperView is { } && SuperView.Subviews.Contains (this)) + if (SuperView is { } && SuperView.SubViews.Contains (this)) { Text = string.Empty; SetNeedsDraw (); @@ -513,7 +513,7 @@ private void HideList () Reset (true); _listview.ClearViewport (); _listview.TabStop = TabBehavior.NoStop; - SuperView?.MoveSubviewToStart (this); + SuperView?.MoveSubViewToStart (this); // BUGBUG: SetNeedsDraw takes Viewport relative coordinates, not Screen Rectangle rect = _listview.ViewportToScreen (_listview.IsInitialized ? _listview.Viewport : Rectangle.Empty); @@ -658,7 +658,7 @@ private void Reset (bool keepSearchText = false) _listview.SetSource (_searchSet); _listview.Height = CalculateHeight (); - if (Subviews.Count > 0 && HasFocus) + if (SubViews.Count > 0 && HasFocus) { _search.SetFocus (); } @@ -814,7 +814,7 @@ private void ShowList () _listview.ClearViewport (); _listview.Height = CalculateHeight (); - SuperView?.MoveSubviewToStart (this); + SuperView?.MoveSubViewToStart (this); } private bool UnixEmulation () diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index b80dcacabe..b21da3d12c 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -505,7 +505,7 @@ public override void OnLoaded () { _btnCancel.X = Pos.Func (CalculateOkButtonPosX); _btnOk.X = Pos.Right (_btnCancel) + 1; - MoveSubviewTowardsStart (_btnCancel); + MoveSubViewTowardsStart (_btnCancel); } SetNeedsDraw (); diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index c2efbb7de0..0045d901a6 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -106,10 +106,10 @@ public HexView (Stream? source) MouseBindings.Add (MouseFlags.WheeledUp, Command.ScrollUp); MouseBindings.Add (MouseFlags.WheeledDown, Command.ScrollDown); - SubviewsLaidOut += HexViewSubviewsLaidOut; + SubViewsLaidOut += HexViewSubViewsLaidOut; } - private void HexViewSubviewsLaidOut (object? sender, LayoutEventArgs e) + private void HexViewSubViewsLaidOut (object? sender, LayoutEventArgs e) { SetBytesPerLine (); SetContentSize (new (GetLeftSideStartColumn () + BytesPerLine / NUM_BYTES_PER_HEX_COLUMN * HEX_COLUMN_WIDTH + BytesPerLine - 1, (int)((GetEditedSize ()) / BytesPerLine) + 1)); diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 2e8ccbc829..d2efb8d2be 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -1,10 +1,10 @@ namespace Terminal.Gui; /// -/// The Label displays text that describes the View next in the . When +/// The Label displays text that describes the View next in the . When /// Label /// receives a command it will pass it to the next in -/// . +/// . /// /// /// @@ -13,7 +13,7 @@ /// /// If is and the use clicks on the Label, /// the will be invoked on the next in -/// . +/// . /// /// public class Label : View, IDesignable @@ -75,12 +75,12 @@ public override Rune HotKeySpecifier if (HotKey.IsValid) { - int me = SuperView?.Subviews.IndexOf (this) ?? -1; + int me = SuperView?.SubViews.IndexOf (this) ?? -1; - if (me != -1 && me < SuperView?.Subviews.Count - 1) + if (me != -1 && me < SuperView?.SubViews.Count - 1) { - return SuperView?.Subviews [me + 1].InvokeCommand (Command.HotKey) == true; + return SuperView?.SubViews.ElementAt (me + 1).InvokeCommand (Command.HotKey) == true; } } diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index a9b0676dd8..6084df0d6c 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -84,7 +84,7 @@ public MenuBar () WantMousePositionReports = true; IsMenuOpen = false; - Added += MenuBar_Added; + SuperViewChanged += MenuBar_SuperViewChanged; // Things this view knows how to do AddCommand ( @@ -559,7 +559,7 @@ private void CloseOtherOpenedMenuBar () if (Application.Top is { }) { // Close others menu bar opened - Menu? menu = Application.Top.Subviews.FirstOrDefault (v => v is Menu m && m.Host != this && m.Host.IsMenuOpen) as Menu; + Menu? menu = Application.Top.SubViews.FirstOrDefault (v => v is Menu m && m.Host != this && m.Host.IsMenuOpen) as Menu; menu?.Host.CleanUp (); } } @@ -1157,10 +1157,10 @@ private Point GetLocationOffset () return new (-2, 0); } - private void MenuBar_Added (object? sender, SuperViewChangedEventArgs e) + private void MenuBar_SuperViewChanged (object? sender, SuperViewChangedEventArgs _) { _initialCanFocus = CanFocus; - Added -= MenuBar_Added; + SuperViewChanged -= MenuBar_SuperViewChanged; } private void MoveLeft () diff --git a/Terminal.Gui/Views/MenuBarv2.cs b/Terminal.Gui/Views/MenuBarv2.cs index 7eb470968b..4f1434c348 100644 --- a/Terminal.Gui/Views/MenuBarv2.cs +++ b/Terminal.Gui/Views/MenuBarv2.cs @@ -22,7 +22,7 @@ public MenuBarv2 (IEnumerable shortcuts) : base (shortcuts) ColorScheme = Colors.ColorSchemes ["Menu"]; Orientation = Orientation.Horizontal; - SubviewLayout += MenuBarv2_LayoutStarted; + SubViewLayout += MenuBarv2_LayoutStarted; } // MenuBarv2 arranges the items horizontally. @@ -34,14 +34,11 @@ private void MenuBarv2_LayoutStarted (object sender, LayoutEventArgs e) } /// - public override View Add (View view) + protected override void OnSubViewAdded (View subView) { - // Call base first, because otherwise it resets CanFocus to true - base.Add (view); + subView.CanFocus = false; - view.CanFocus = true; - - if (view is Shortcut shortcut) + if (subView is Shortcut shortcut) { // TODO: not happy about using AlignmentModes for this. Too implied. // TODO: instead, add a property (a style enum?) to Shortcut to control this @@ -50,7 +47,5 @@ public override View Add (View view) shortcut.KeyView.Visible = false; shortcut.HelpView.Visible = false; } - - return view; } } diff --git a/Terminal.Gui/Views/Menuv2.cs b/Terminal.Gui/Views/Menuv2.cs index 609fb962c2..e9d85ed41a 100644 --- a/Terminal.Gui/Views/Menuv2.cs +++ b/Terminal.Gui/Views/Menuv2.cs @@ -47,11 +47,11 @@ private void Menuv2_Initialized (object sender, EventArgs e) // The first item has no left border, the last item has no right border. // The Shortcuts are configured with the command, help, and key views aligned in reverse order (EndToStart). /// - protected override void OnSubviewLayout (LayoutEventArgs args) + protected override void OnSubViewLayout (LayoutEventArgs args) { - for (int index = 0; index < Subviews.Count; index++) + for (int index = 0; index < SubViews.Count; index++) { - View barItem = Subviews [index]; + View barItem = SubViews.ElementAt (index); if (!barItem.Visible) { @@ -59,15 +59,14 @@ protected override void OnSubviewLayout (LayoutEventArgs args) } } - base.OnSubviewLayout (args); + base.OnSubViewLayout (args); } /// - public override View Add (View view) + /// + protected override void OnSubViewAdded (View subView) { - base.Add (view); - - if (view is Shortcut shortcut) + if (subView is Shortcut shortcut) { shortcut.CanFocus = true; shortcut.Orientation = Orientation.Vertical; @@ -95,7 +94,5 @@ void ShortcutOnAccept (object sender, CommandEventArgs e) //} } } - - return view; } } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 015157dc69..5fc2b2c1b2 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -42,7 +42,7 @@ public RadioGroup () // By default, single click is already bound to Command.Select MouseBindings.Add (MouseFlags.Button1DoubleClicked, Command.Accept); - SubviewLayout += RadioGroup_LayoutStarted; + SubViewLayout += RadioGroup_LayoutStarted; HighlightStyle = HighlightStyle.PressedOutside | HighlightStyle.Pressed; } diff --git a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs index 44b50fb09a..1d9885c2af 100644 --- a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs @@ -113,7 +113,7 @@ private void ShowHide () _slider.Position = _sliderPosition.Value; } - private void PositionSubviews () + private void PositionSubViews () { if (Orientation == Orientation.Vertical) { @@ -180,7 +180,7 @@ public void OnOrientationChanged (Orientation newOrientation) TextAlignment = Alignment.Center; VerticalTextAlignment = Alignment.Center; _slider.Orientation = newOrientation; - PositionSubviews (); + PositionSubViews (); OrientationChanged?.Invoke (this, new (newOrientation)); } diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs index 9cb02ca3cf..342d544563 100644 --- a/Terminal.Gui/Views/Shortcut.cs +++ b/Terminal.Gui/Views/Shortcut.cs @@ -132,7 +132,7 @@ public Shortcut (Key key, string? commandText, Action? action, string? helpText Action = action; - SubviewLayout += OnLayoutStarted; + SubViewLayout += OnLayoutStarted; ShowHide (); } @@ -221,7 +221,7 @@ private void ForceCalculateNaturalWidth () HelpView.SetRelativeLayout (Application.Screen.Size); KeyView.SetRelativeLayout (Application.Screen.Size); - _minimumNaturalWidth = PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width); + _minimumNaturalWidth = PosAlign.CalculateMinDimension (0, SubViews, Dimension.Width); // Reset our relative layout SetRelativeLayout (SuperView?.GetContentSize () ?? Application.Screen.Size); @@ -824,17 +824,17 @@ protected override void Dispose (bool disposing) { TitleChanged -= Shortcut_TitleChanged; - if (CommandView?.IsAdded == false) + if (CommandView.SuperView is null) { CommandView.Dispose (); } - if (HelpView?.IsAdded == false) + if (HelpView.SuperView is null) { HelpView.Dispose (); } - if (KeyView?.IsAdded == false) + if (KeyView.SuperView is null) { KeyView.Dispose (); } diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 2008f22e49..a0cc6b3356 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -59,7 +59,7 @@ private void SetInitialProperties ( // BUGBUG: This should not be needed - Need to ensure SetRelativeLayout gets called during EndInit Initialized += (s, e) => { SetContentSize (); }; - SubviewLayout += (s, e) => { SetContentSize (); }; + SubViewLayout += (s, e) => { SetContentSize (); }; } // TODO: Make configurable via ConfigurationManager diff --git a/Terminal.Gui/Views/SpinnerView/SpinnerView.cs b/Terminal.Gui/Views/SpinnerView/SpinnerView.cs index a16f88a269..f040bc8070 100644 --- a/Terminal.Gui/Views/SpinnerView/SpinnerView.cs +++ b/Terminal.Gui/Views/SpinnerView/SpinnerView.cs @@ -1,16 +1,15 @@ -//------------------------------------------------------------------------------ +#nullable enable +//------------------------------------------------------------------------------ // Windows Terminal supports Unicode and Emoji characters, but by default // conhost shells (e.g., PowerShell and cmd.exe) do not. See // . //------------------------------------------------------------------------------ -using System.Diagnostics; - namespace Terminal.Gui; /// A which displays (by default) a spinning line character. /// -/// By default animation only occurs when you call . Use +/// By default, animation only occurs when you call . Use /// to make the automate calls to . /// public class SpinnerView : View, IDesignable @@ -25,7 +24,7 @@ public class SpinnerView : View, IDesignable private DateTime _lastRender = DateTime.MinValue; private string [] _sequence = DEFAULT_STYLE.Sequence; private SpinnerStyle _style = DEFAULT_STYLE; - private object _timeout; + private object? _timeout; /// Creates a new instance of the class. public SpinnerView () @@ -134,14 +133,7 @@ public void AdvanceAnimation (bool setNeedsDraw = true) { if (SpinBounce) { - if (SpinReverse) - { - _bounceReverse = false; - } - else - { - _bounceReverse = true; - } + _bounceReverse = !SpinReverse; _currentIdx = Sequence.Length - 1; } @@ -155,14 +147,7 @@ public void AdvanceAnimation (bool setNeedsDraw = true) { if (SpinBounce) { - if (SpinReverse) - { - _bounceReverse = true; - } - else - { - _bounceReverse = false; - } + _bounceReverse = SpinReverse; _currentIdx = 1; } @@ -182,25 +167,26 @@ public void AdvanceAnimation (bool setNeedsDraw = true) } } - /// + /// protected override bool OnClearingViewport () { return true; } - /// + /// protected override bool OnDrawingContent () { Render (); + return true; } /// - /// Renders the current frame of the spinner. + /// Renders the current frame of the spinner. /// public void Render () { if (Sequence is { Length: > 0 } && _currentIdx < Sequence.Length) { Move (Viewport.X, Viewport.Y); - View.Driver?.AddStr (Sequence [_currentIdx]); + Driver?.AddStr (Sequence [_currentIdx]); } } @@ -214,7 +200,8 @@ protected override void Dispose (bool disposing) private void AddAutoSpinTimeout () { - if (_timeout is { }) + // Only add timeout if we are initialized and not already spinning + if (_timeout is { } || !Application.Initialized) { return; } @@ -223,7 +210,7 @@ private void AddAutoSpinTimeout () TimeSpan.FromMilliseconds (SpinDelay), () => { - Application.Invoke (() => AdvanceAnimation()); + Application.Invoke (() => AdvanceAnimation ()); return true; } @@ -237,7 +224,7 @@ private bool GetIsAsciiOnly () return false; } - if (_sequence is { } && _sequence.Length > 0) + if (_sequence is { Length: > 0 }) { foreach (string frame in _sequence) { @@ -260,7 +247,7 @@ private int GetSpinnerWidth () { var max = 0; - if (_sequence is { } && _sequence.Length > 0) + if (_sequence is { Length: > 0 }) { foreach (string frame in _sequence) { @@ -295,7 +282,7 @@ private void SetDelay (int delay) private void SetSequence (string [] frames) { - if (frames is { } && frames.Length > 0) + if (frames is { Length: > 0 }) { _style = new SpinnerStyle.Custom (); _sequence = frames; @@ -303,7 +290,7 @@ private void SetSequence (string [] frames) } } - private void SetStyle (SpinnerStyle style) + private void SetStyle (SpinnerStyle? style) { if (style is { }) { @@ -320,6 +307,7 @@ bool IDesignable.EnableForDesign () Style = new SpinnerStyle.Points (); SpinReverse = true; AutoSpin = true; + return true; } } diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 84914ab558..57743989f6 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -26,7 +26,7 @@ public StatusBar (IEnumerable shortcuts) : base (shortcuts) BorderStyle = LineStyle.Dashed; ColorScheme = Colors.ColorSchemes ["Menu"]; - SubviewLayout += StatusBar_LayoutStarted; + SubViewLayout += StatusBar_LayoutStarted; } // StatusBar arranges the items horizontally. @@ -34,13 +34,13 @@ public StatusBar (IEnumerable shortcuts) : base (shortcuts) // The Shortcuts are configured with the command, help, and key views aligned in reverse order (EndToStart). private void StatusBar_LayoutStarted (object sender, LayoutEventArgs e) { - for (int index = 0; index < Subviews.Count; index++) + for (int index = 0; index < SubViews.Count; index++) { - View barItem = Subviews [index]; + View barItem = SubViews.ElementAt (index); barItem.BorderStyle = BorderStyle; - if (index == Subviews.Count - 1) + if (index == SubViews.Count - 1) { barItem.Border.Thickness = new Thickness (0, 0, 0, 0); } @@ -57,21 +57,16 @@ private void StatusBar_LayoutStarted (object sender, LayoutEventArgs e) } /// - public override View Add (View view) + protected override void OnSubViewAdded (View subView) { - // Call base first, because otherwise it resets CanFocus to true - base.Add (view); + subView.CanFocus = false; - view.CanFocus = false; - - if (view is Shortcut shortcut) + if (subView is Shortcut shortcut) { // TODO: not happy about using AlignmentModes for this. Too implied. // TODO: instead, add a property (a style enum?) to Shortcut to control this shortcut.AlignmentModes = AlignmentModes.EndToStart; } - - return view; } /// diff --git a/Terminal.Gui/Views/TabView/TabRow.cs b/Terminal.Gui/Views/TabView/TabRow.cs index 2ca80a69ae..a34d4075db 100644 --- a/Terminal.Gui/Views/TabView/TabRow.cs +++ b/Terminal.Gui/Views/TabView/TabRow.cs @@ -115,7 +115,7 @@ protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocus } /// - protected override void OnSubviewLayout (LayoutEventArgs args) + protected override void OnSubViewLayout (LayoutEventArgs args) { _host._tabLocations = _host.CalculateViewport (Viewport).ToArray (); @@ -123,7 +123,7 @@ protected override void OnSubviewLayout (LayoutEventArgs args) RenderUnderline (); - base.OnSubviewLayout (args); + base.OnSubViewLayout (args); } /// @@ -765,7 +765,7 @@ private void RenderUnderline () _leftScrollIndicator.Visible = true; // Ensures this is clicked instead of the first tab - MoveSubviewToEnd (_leftScrollIndicator); + MoveSubViewToEnd (_leftScrollIndicator); } else { @@ -782,7 +782,7 @@ private void RenderUnderline () _rightScrollIndicator.Visible = true; // Ensures this is clicked instead of the last tab if under this - MoveSubviewToStart (_rightScrollIndicator); + MoveSubViewToStart (_rightScrollIndicator); } else { diff --git a/Terminal.Gui/Views/TabView/TabView.cs b/Terminal.Gui/Views/TabView/TabView.cs index 73f286b564..5dc14b8bf6 100644 --- a/Terminal.Gui/Views/TabView/TabView.cs +++ b/Terminal.Gui/Views/TabView/TabView.cs @@ -160,7 +160,7 @@ private bool TabCanSetFocus () private void ContainerViewCanFocus (object sender, EventArgs eventArgs) { - _containerView.CanFocus = _containerView.Subviews.Count (v => v.CanFocus) > 0; + _containerView.CanFocus = _containerView.SubViews.Count (v => v.CanFocus) > 0; } private TabStyle _style = new (); diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 5bb386ca72..6c872d95c4 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -45,9 +45,7 @@ public TextField () Initialized += TextField_Initialized; - Added += TextField_Added; - - Removed += TextField_Removed; + SuperViewChanged += TextField_SuperViewChanged; // Things this view knows how to do AddCommand ( @@ -1182,7 +1180,7 @@ public void Undo () private void Adjust () { - if (!IsAdded) + if (SuperView is null) { return; } @@ -1820,17 +1818,22 @@ private void ShowContextMenu () ContextMenu.Show (BuildContextMenuBarItem ()); } - private void TextField_Added (object sender, SuperViewChangedEventArgs e) + private void TextField_SuperViewChanged (object sender, SuperViewChangedEventArgs e) { - if (Autocomplete.HostControl is null) + if (e.SuperView is {}) { - Autocomplete.HostControl = this; - Autocomplete.PopupInsideContainer = false; + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + Autocomplete.PopupInsideContainer = false; + } + } + else + { + Autocomplete.HostControl = null; } } - private void TextField_Removed (object sender, SuperViewChangedEventArgs e) { Autocomplete.HostControl = null; } - private void TextField_Initialized (object sender, EventArgs e) { _cursorPosition = Text.GetRuneCount (); diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 0dbd1f960f..af0d74226c 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1899,9 +1899,9 @@ public TextView () Initialized += TextView_Initialized!; - Added += TextView_Added!; + SuperViewChanged += TextView_SuperViewChanged!; - SubviewsLaidOut += TextView_LayoutComplete; + SubViewsLaidOut += TextView_LayoutComplete; // Things this view knows how to do @@ -2416,8 +2416,6 @@ public TextView () KeyBindings.Add (ContextMenu.Key, Command.Context); } - private void TextView_Added1 (object? sender, SuperViewChangedEventArgs e) { throw new NotImplementedException (); } - // BUGBUG: AllowsReturn is mis-named. It should be EnterKeyAccepts. /// /// Gets or sets whether pressing ENTER in a creates a new line of text @@ -6444,11 +6442,18 @@ private string StringFromRunes (List cells) return StringExtensions.ToString (encoded); } - private void TextView_Added (object sender, SuperViewChangedEventArgs e) + private void TextView_SuperViewChanged (object sender, SuperViewChangedEventArgs e) { - if (Autocomplete.HostControl is null) + if (e.SuperView is {}) { - Autocomplete.HostControl = this; + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + } + } + else + { + Autocomplete.HostControl = null; } } diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index c2693f1914..f3aed9c2ab 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -23,7 +23,7 @@ public TileView (int tiles) CanFocus = true; RebuildForTileCount (tiles); - SubviewLayout += (_, _) => + SubViewLayout += (_, _) => { Rectangle viewport = Viewport; @@ -100,14 +100,14 @@ public int IndexOf (View toFind, bool recursive = false) return i; } - if (v.Subviews.Contains (toFind)) + if (v.SubViews.Contains (toFind)) { return i; } if (recursive) { - if (RecursiveContains (v.Subviews, toFind)) + if (RecursiveContains (v.SubViews, toFind)) { return i; } @@ -485,7 +485,7 @@ public bool TrySplitTile (int idx, int numberOfPanels, out TileView result) }; // Take everything out of the View we are moving - View [] childViews = toMove!.Subviews.ToArray (); + View [] childViews = toMove!.SubViews.ToArray (); toMove.RemoveAll (); // Remove the view itself and replace it with the new TileView @@ -533,7 +533,7 @@ private List GetAllLineViewsRecursively (View v) { List lines = new (); - foreach (View sub in v.Subviews) + foreach (View sub in v.SubViews) { if (sub is TileViewLineView s) { @@ -756,7 +756,7 @@ private bool RecursiveContains (IEnumerable haystack, View needle) return true; } - if (RecursiveContains (v.Subviews, needle)) + if (RecursiveContains (v.SubViews, needle)) { return true; } diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 7861fcfd0b..47ad49ab33 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -33,7 +33,7 @@ public Toplevel () Arrangement = ViewArrangement.Overlapped; Width = Dim.Fill (); Height = Dim.Fill (); - ColorScheme = Colors.ColorSchemes ["TopLevel"]; + base.ColorScheme = Colors.ColorSchemes ["TopLevel"]; MouseClick += Toplevel_MouseClick; } @@ -66,15 +66,15 @@ public Toplevel () #endregion - #region Subviews + #region SubViews // TODO: Deprecate - Any view can host a menubar in v2 /// Gets the latest added into this Toplevel. - public MenuBar? MenuBar => (MenuBar?)Subviews?.LastOrDefault (s => s is MenuBar); + public MenuBar? MenuBar => (MenuBar?)SubViews?.LastOrDefault (s => s is MenuBar); //// TODO: Deprecate - Any view can host a statusbar in v2 ///// Gets the latest added into this Toplevel. - //public StatusBar? StatusBar => (StatusBar?)Subviews?.LastOrDefault (s => s is StatusBar); + //public StatusBar? StatusBar => (StatusBar?)SubViews?.LastOrDefault (s => s is StatusBar); #endregion @@ -127,7 +127,7 @@ public virtual void OnLoaded () { IsLoaded = true; - foreach (var view in Subviews.Where (v => v is Toplevel)) + foreach (var view in SubViews.Where (v => v is Toplevel)) { var tl = (Toplevel)view; tl.OnLoaded (); @@ -180,7 +180,7 @@ internal virtual bool OnClosing (ToplevelClosingEventArgs ev) /// internal virtual void OnReady () { - foreach (var view in Subviews.Where (v => v is Toplevel)) + foreach (var view in SubViews.Where (v => v is Toplevel)) { var tl = (Toplevel)view; tl.OnReady (); @@ -192,7 +192,7 @@ internal virtual void OnReady () /// Called from before the is disposed. internal virtual void OnUnloaded () { - foreach (var view in Subviews.Where (v => v is Toplevel)) + foreach (var view in SubViews.Where (v => v is Toplevel)) { var tl = (Toplevel)view; tl.OnUnloaded (); @@ -202,7 +202,7 @@ internal virtual void OnUnloaded () } #endregion - + #region Size / Position Management // TODO: Make cancelable? @@ -235,7 +235,7 @@ out int ny return; } - //var layoutSubviews = false; + //var layoutSubViews = false; var maxWidth = 0; if (superView.Margin is { } && superView == top.SuperView) @@ -251,25 +251,25 @@ out int ny if (top?.X is null or PosAbsolute && top?.Frame.X != nx) { top!.X = nx; - //layoutSubviews = true; + //layoutSubViews = true; } if (top?.Y is null or PosAbsolute && top?.Frame.Y != ny) { top!.Y = ny; - //layoutSubviews = true; + //layoutSubViews = true; } } - //if (superView.IsLayoutNeeded () || layoutSubviews) + //if (superView.IsLayoutNeeded () || layoutSubViews) //{ - // superView.LayoutSubviews (); + // superView.LayoutSubViews (); //} //if (IsLayoutNeeded ()) //{ - // LayoutSubviews (); + // LayoutSubViews (); //} } diff --git a/Terminal.Gui/Views/Wizard/Wizard.cs b/Terminal.Gui/Views/Wizard/Wizard.cs index 2155c7cc14..0bff72f2f7 100644 --- a/Terminal.Gui/Views/Wizard/Wizard.cs +++ b/Terminal.Gui/Views/Wizard/Wizard.cs @@ -357,7 +357,7 @@ public bool GoToStep (WizardStep? newStep) UpdateButtonsAndTitle (); // Set focus on the contentview - newStep?.Subviews.ToArray () [0].SetFocus (); + newStep?.SubViews.ToArray () [0].SetFocus (); if (OnStepChanged (oldStep, _currentStep)) { @@ -501,7 +501,7 @@ private void SizeStep (WizardStep step) step.Height = Dim.Fill ( Dim.Func ( () => IsInitialized - ? Subviews.First (view => view.Y.Has (out _)).Frame.Height + 1 + ? SubViews.First (view => view.Y.Has (out _)).Frame.Height + 1 : 1)); // for button frame (+1 for lineView) step.Width = Dim.Fill (); } @@ -513,7 +513,7 @@ private void SizeStep (WizardStep step) step.Height = Dim.Fill ( Dim.Func ( () => IsInitialized - ? Subviews.First (view => view.Y.Has (out _)).Frame.Height + 1 + ? SubViews.First (view => view.Y.Has (out _)).Frame.Height + 1 : 2)); // for button frame (+1 for lineView) step.Width = Dim.Fill (); } diff --git a/Terminal.Gui/Views/Wizard/WizardStep.cs b/Terminal.Gui/Views/Wizard/WizardStep.cs index afb750ffba..cf1b781da7 100644 --- a/Terminal.Gui/Views/Wizard/WizardStep.cs +++ b/Terminal.Gui/Views/Wizard/WizardStep.cs @@ -88,7 +88,7 @@ public WizardStep () // scrollBar.OtherScrollBarView.Size = helpTextView.Maxlength; // scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; // } - // scrollBar.LayoutSubviews (); + // scrollBar.LayoutSubViews (); // scrollBar.Refresh (); //}; //base.Add (scrollBar); @@ -151,7 +151,7 @@ public override View Add (View? view) container?.Remove (view); } - if (_contentView.InternalSubviews.Count < 1) + if (_contentView.InternalSubViews.Count < 1) { CanFocus = false; } @@ -176,7 +176,7 @@ internal void ShowHide () _helpTextView.Height = Dim.Height(_contentView); _helpTextView.Width = Dim.Fill (); - if (_contentView.InternalSubviews?.Count > 0) + if (_contentView.InternalSubViews?.Count > 0) { if (_helpTextView.Text.Length > 0) { @@ -199,7 +199,7 @@ internal void ShowHide () // Error - no pane shown } - _contentView.Visible = _contentView.InternalSubviews?.Count > 0; + _contentView.Visible = _contentView.InternalSubViews?.Count > 0; _helpTextView.Visible = _helpTextView.Text.Length > 0; } } // end of WizardStep class diff --git a/Terminal.sln.DotSettings b/Terminal.sln.DotSettings index 7b9a335a8c..5102526225 100644 --- a/Terminal.sln.DotSettings +++ b/Terminal.sln.DotSettings @@ -410,8 +410,10 @@ True True 5 + True True True + True True True True diff --git a/Tests/IntegrationTests/UICatalog/ScenarioTests.cs b/Tests/IntegrationTests/UICatalog/ScenarioTests.cs index 3de2735f43..02ce55e619 100644 --- a/Tests/IntegrationTests/UICatalog/ScenarioTests.cs +++ b/Tests/IntegrationTests/UICatalog/ScenarioTests.cs @@ -2,8 +2,8 @@ using System.Diagnostics; using System.Reflection; using Terminal.Gui; -using UnitTests; using UICatalog; +using UnitTests; using Xunit.Abstractions; namespace IntegrationTests.UICatalog; @@ -21,7 +21,7 @@ public ScenarioTests (ITestOutputHelper output) private readonly ITestOutputHelper _output; - private object _timeoutLock; + private object? _timeoutLock; /// /// This runs through all Scenarios defined in UI Catalog, calling Init, Setup, and Run. @@ -42,18 +42,18 @@ public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType) Application.ResetState (true); _output.WriteLine ($"Running Scenario '{scenarioType}'"); - var scenario = (Scenario)Activator.CreateInstance (scenarioType); + var scenario = Activator.CreateInstance (scenarioType) as Scenario; uint abortTime = 1500; - object timeout = null; + object? timeout = null; var initialized = false; var shutdown = false; - int iterationCount = 0; + var iterationCount = 0; Application.InitializedChanged += OnApplicationOnInitializedChanged; Application.ForceDriver = "FakeDriver"; - scenario.Main (); + scenario!.Main (); scenario.Dispose (); scenario = null; Application.ForceDriver = string.Empty; @@ -83,9 +83,10 @@ public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType) // Restore the configuration locations ConfigurationManager.Locations = savedConfigLocations; ConfigurationManager.Reset (); + return; - void OnApplicationOnInitializedChanged (object s, EventArgs a) + void OnApplicationOnInitializedChanged (object? s, EventArgs a) { if (a.CurrentValue) { @@ -96,13 +97,13 @@ void OnApplicationOnInitializedChanged (object s, EventArgs a) { timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback); } - } else { Application.Iteration -= OnApplicationOnIteration; shutdown = true; } + _output.WriteLine ($"Initialized == {a.CurrentValue}"); } @@ -118,7 +119,7 @@ bool ForceCloseCallback () } Assert.Fail ( - $"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms and {iterationCount} iterations. Force quit."); + $"Scenario Failed to Quit with {Application.QuitKey} after {abortTime}ms and {iterationCount} iterations. Force quit."); // Restore the configuration locations ConfigurationManager.Locations = savedConfigLocations; @@ -129,9 +130,10 @@ bool ForceCloseCallback () return false; } - void OnApplicationOnIteration (object s, IterationEventArgs a) + void OnApplicationOnIteration (object? s, IterationEventArgs a) { iterationCount++; + if (Application.Initialized) { // Press QuitKey @@ -141,7 +143,6 @@ void OnApplicationOnIteration (object s, IterationEventArgs a) } } - public static IEnumerable AllScenarioTypes => typeof (Scenario).Assembly .GetTypes () @@ -155,40 +156,24 @@ public void Run_All_Views_Tester_Scenario () ConfigLocations savedConfigLocations = ConfigurationManager.Locations; ConfigurationManager.Locations = ConfigLocations.Default; - Window _leftPane; - ListView _classListView; - FrameView _hostPane; - - Dictionary _viewClasses; - View _curView = null; + View? curView = null; // Settings - FrameView _settingsPane; - FrameView _locationFrame; - RadioGroup _xRadioGroup; - TextField _xText; - var _xVal = 0; - RadioGroup _yRadioGroup; - TextField _yText; - var _yVal = 0; - - FrameView _sizeFrame; - RadioGroup _wRadioGroup; - TextField _wText; - var _wVal = 0; - RadioGroup _hRadioGroup; - TextField _hText; - var _hVal = 0; - List posNames = new () { "Percent", "AnchorEnd", "Center", "Absolute" }; - List dimNames = new () { "Auto", "Percent", "Fill", "Absolute" }; + var xVal = 0; + var yVal = 0; + + var wVal = 0; + var hVal = 0; + List posNames = ["Percent", "AnchorEnd", "Center", "Absolute"]; + List dimNames = ["Auto", "Percent", "Fill", "Absolute"]; Application.Init (new FakeDriver ()); var top = new Toplevel (); - _viewClasses = ViewTestHelpers.GetAllViewClasses ().ToDictionary (t => t.Name); + Dictionary viewClasses = GetAllViewClasses().ToDictionary (t => t.Name); - _leftPane = new () + Window leftPane = new () { Title = "Classes", X = 0, @@ -199,7 +184,7 @@ public void Run_All_Views_Tester_Scenario () ColorScheme = Colors.ColorSchemes ["TopLevel"] }; - _classListView = new () + ListView classListView = new () { X = 0, Y = 0, @@ -207,13 +192,13 @@ public void Run_All_Views_Tester_Scenario () Height = Dim.Fill (), AllowsMarking = false, ColorScheme = Colors.ColorSchemes ["TopLevel"], - Source = new ListWrapper (new (_viewClasses.Keys.ToList ())) + Source = new ListWrapper (new (viewClasses.Keys.ToList ())) }; - _leftPane.Add (_classListView); + leftPane.Add (classListView); - _settingsPane = new () + FrameView settingsPane = new () { - X = Pos.Right (_leftPane), + X = Pos.Right (leftPane), Y = 0, // for menu Width = Dim.Fill (), Height = 10, @@ -224,7 +209,7 @@ public void Run_All_Views_Tester_Scenario () var radioItems = new [] { "Percent(x)", "AnchorEnd(x)", "Center", "Absolute(x)" }; - _locationFrame = new () + FrameView locationFrame = new () { X = 0, Y = 0, @@ -232,28 +217,28 @@ public void Run_All_Views_Tester_Scenario () Width = 36, Title = "Location (Pos)" }; - _settingsPane.Add (_locationFrame); + settingsPane.Add (locationFrame); var label = new Label { X = 0, Y = 0, Text = "x:" }; - _locationFrame.Add (label); - _xRadioGroup = new () { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; - _xText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_xVal}" }; - _locationFrame.Add (_xText); + locationFrame.Add (label); + RadioGroup xRadioGroup = new () { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; + TextField xText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{xVal}" }; + locationFrame.Add (xText); - _locationFrame.Add (_xRadioGroup); + locationFrame.Add (xRadioGroup); radioItems = new [] { "Percent(y)", "AnchorEnd(y)", "Center", "Absolute(y)" }; - label = new () { X = Pos.Right (_xRadioGroup) + 1, Y = 0, Text = "y:" }; - _locationFrame.Add (label); - _yText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_yVal}" }; - _locationFrame.Add (_yText); - _yRadioGroup = new () { X = Pos.X (label), Y = Pos.Bottom (label), RadioLabels = radioItems }; - _locationFrame.Add (_yRadioGroup); - - _sizeFrame = new () + label = new () { X = Pos.Right (xRadioGroup) + 1, Y = 0, Text = "y:" }; + locationFrame.Add (label); + TextField yText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{yVal}" }; + locationFrame.Add (yText); + RadioGroup yRadioGroup = new () { X = Pos.X (label), Y = Pos.Bottom (label), RadioLabels = radioItems }; + locationFrame.Add (yRadioGroup); + + FrameView sizeFrame = new () { - X = Pos.Right (_locationFrame), - Y = Pos.Y (_locationFrame), + X = Pos.Right (locationFrame), + Y = Pos.Y (locationFrame), Height = 3 + radioItems.Length, Width = 40, Title = "Size (Dim)" @@ -261,131 +246,131 @@ public void Run_All_Views_Tester_Scenario () radioItems = new [] { "Auto()", "Percent(width)", "Fill(width)", "Absolute(width)" }; label = new () { X = 0, Y = 0, Text = "width:" }; - _sizeFrame.Add (label); - _wRadioGroup = new () { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; - _wText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_wVal}" }; - _sizeFrame.Add (_wText); - _sizeFrame.Add (_wRadioGroup); + sizeFrame.Add (label); + RadioGroup wRadioGroup = new () { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; + TextField wText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{wVal}" }; + sizeFrame.Add (wText); + sizeFrame.Add (wRadioGroup); radioItems = new [] { "Auto()", "Percent(height)", "Fill(height)", "Absolute(height)" }; - label = new () { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "height:" }; - _sizeFrame.Add (label); - _hText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; - _sizeFrame.Add (_hText); + label = new () { X = Pos.Right (wRadioGroup) + 1, Y = 0, Text = "height:" }; + sizeFrame.Add (label); + TextField hText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{hVal}" }; + sizeFrame.Add (hText); - _hRadioGroup = new () { X = Pos.X (label), Y = Pos.Bottom (label), RadioLabels = radioItems }; - _sizeFrame.Add (_hRadioGroup); + RadioGroup hRadioGroup = new () { X = Pos.X (label), Y = Pos.Bottom (label), RadioLabels = radioItems }; + sizeFrame.Add (hRadioGroup); - _settingsPane.Add (_sizeFrame); + settingsPane.Add (sizeFrame); - _hostPane = new () + FrameView hostPane = new () { - X = Pos.Right (_leftPane), - Y = Pos.Bottom (_settingsPane), + X = Pos.Right (leftPane), + Y = Pos.Bottom (settingsPane), Width = Dim.Fill (), Height = Dim.Fill (1), // + 1 for status bar ColorScheme = Colors.ColorSchemes ["Dialog"] }; - _classListView.OpenSelectedItem += (s, a) => { _settingsPane.SetFocus (); }; - - _classListView.SelectedItemChanged += (s, args) => - { - // Remove existing class, if any - if (_curView != null) - { - _curView.SubviewsLaidOut -= LayoutCompleteHandler; - _hostPane.Remove (_curView); - _curView.Dispose (); - _curView = null; - _hostPane.FillRect (_hostPane.Viewport); - } - - _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); - }; - - _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - - _xText.TextChanged += (s, args) => - { - try - { - _xVal = int.Parse (_xText.Text); - DimPosChanged (_curView); - } - catch - { } - }; - - _yText.TextChanged += (s, e) => - { - try - { - _yVal = int.Parse (_yText.Text); - DimPosChanged (_curView); - } - catch - { } - }; - - _yRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - - _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - - _wText.TextChanged += (s, args) => - { - try - { - _wVal = int.Parse (_wText.Text); - DimPosChanged (_curView); - } - catch - { } - }; - - _hText.TextChanged += (s, args) => - { - try - { - _hVal = int.Parse (_hText.Text); - DimPosChanged (_curView); - } - catch - { } - }; - - _hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - - top.Add (_leftPane, _settingsPane, _hostPane); - - top.LayoutSubviews (); - - _curView = CreateClass (_viewClasses.First ().Value); + classListView.OpenSelectedItem += (s, a) => { settingsPane.SetFocus (); }; + + classListView.SelectedItemChanged += (s, args) => + { + // Remove existing class, if any + if (curView is {}) + { + curView.SubViewsLaidOut -= LayoutCompleteHandler; + hostPane.Remove (curView); + curView.Dispose (); + curView = null; + hostPane.FillRect (hostPane.Viewport); + } + + curView = CreateClass (viewClasses.Values.ToArray () [classListView.SelectedItem]); + }; + + xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (curView); + + xText.TextChanged += (s, args) => + { + try + { + xVal = int.Parse (xText.Text); + DimPosChanged (curView); + } + catch + { } + }; + + yText.TextChanged += (s, e) => + { + try + { + yVal = int.Parse (yText.Text); + DimPosChanged (curView); + } + catch + { } + }; + + yRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (curView); + + wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (curView); + + wText.TextChanged += (s, args) => + { + try + { + wVal = int.Parse (wText.Text); + DimPosChanged (curView); + } + catch + { } + }; + + hText.TextChanged += (s, args) => + { + try + { + hVal = int.Parse (hText.Text); + DimPosChanged (curView); + } + catch + { } + }; + + hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (curView); + + top.Add (leftPane, settingsPane, hostPane); + + top.LayoutSubViews (); + + curView = CreateClass (viewClasses.First ().Value); var iterations = 0; Application.Iteration += (s, a) => - { - iterations++; - - if (iterations < _viewClasses.Count) - { - _classListView.MoveDown (); - - Assert.Equal ( - _curView.GetType ().Name, - _viewClasses.Values.ToArray () [_classListView.SelectedItem].Name - ); - } - else - { - Application.RequestStop (); - } - }; + { + iterations++; + + if (iterations < viewClasses.Count) + { + classListView.MoveDown (); + + Assert.Equal ( + curView!.GetType ().Name, + viewClasses.Values.ToArray () [classListView.SelectedItem].Name + ); + } + else + { + Application.RequestStop (); + } + }; Application.Run (top); - Assert.Equal (_viewClasses.Count, iterations); + Assert.Equal (viewClasses.Count, iterations); top.Dispose (); Application.Shutdown (); @@ -394,7 +379,7 @@ public void Run_All_Views_Tester_Scenario () ConfigurationManager.Locations = savedConfigLocations; ConfigurationManager.Reset (); - void DimPosChanged (View view) + void DimPosChanged (View? view) { if (view == null) { @@ -403,14 +388,14 @@ void DimPosChanged (View view) try { - switch (_xRadioGroup.SelectedItem) + switch (xRadioGroup.SelectedItem) { case 0: - view.X = Pos.Percent (_xVal); + view.X = Pos.Percent (xVal); break; case 1: - view.X = Pos.AnchorEnd (_xVal); + view.X = Pos.AnchorEnd (xVal); break; case 2: @@ -418,19 +403,19 @@ void DimPosChanged (View view) break; case 3: - view.X = Pos.Absolute (_xVal); + view.X = Pos.Absolute (xVal); break; } - switch (_yRadioGroup.SelectedItem) + switch (yRadioGroup.SelectedItem) { case 0: - view.Y = Pos.Percent (_yVal); + view.Y = Pos.Percent (yVal); break; case 1: - view.Y = Pos.AnchorEnd (_yVal); + view.Y = Pos.AnchorEnd (yVal); break; case 2: @@ -438,39 +423,39 @@ void DimPosChanged (View view) break; case 3: - view.Y = Pos.Absolute (_yVal); + view.Y = Pos.Absolute (yVal); break; } - switch (_wRadioGroup.SelectedItem) + switch (wRadioGroup.SelectedItem) { case 0: - view.Width = Dim.Percent (_wVal); + view.Width = Dim.Percent (wVal); break; case 1: - view.Width = Dim.Fill (_wVal); + view.Width = Dim.Fill (wVal); break; case 2: - view.Width = Dim.Absolute (_wVal); + view.Width = Dim.Absolute (wVal); break; } - switch (_hRadioGroup.SelectedItem) + switch (hRadioGroup.SelectedItem) { case 0: - view.Height = Dim.Percent (_hVal); + view.Height = Dim.Percent (hVal); break; case 1: - view.Height = Dim.Fill (_hVal); + view.Height = Dim.Fill (hVal); break; case 2: - view.Height = Dim.Absolute (_hVal); + view.Height = Dim.Absolute (hVal); break; } @@ -490,8 +475,8 @@ void UpdateSettings (View view) try { - _xRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => x.Contains (s))); - _yRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => y.Contains (s))); + xRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => x.Contains (s))); + yRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => y.Contains (s))); } catch (InvalidOperationException e) { @@ -499,22 +484,22 @@ void UpdateSettings (View view) Debug.WriteLine ($"{e}"); } - _xText.Text = $"{view.Frame.X}"; - _yText.Text = $"{view.Frame.Y}"; + xText.Text = $"{view.Frame.X}"; + yText.Text = $"{view.Frame.Y}"; - var w = view.Width.ToString (); - var h = view.Height.ToString (); + var w = view.Width!.ToString (); + var h = view.Height!.ToString (); - _wRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => w.Contains (s))); - _hRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => h.Contains (s))); + wRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => w.Contains (s))); + hRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => h.Contains (s))); - _wText.Text = $"{view.Frame.Width}"; - _hText.Text = $"{view.Frame.Height}"; + wText.Text = $"{view.Frame.Width}"; + hText.Text = $"{view.Frame.Height}"; } - void UpdateTitle (View view) { _hostPane.Title = $"{view.GetType ().Name} - {view.X}, {view.Y}, {view.Width}, {view.Height}"; } + void UpdateTitle (View? view) { hostPane.Title = $"{view!.GetType ().Name} - {view.X}, {view.Y}, {view.Width}, {view.Height}"; } - View CreateClass (Type type) + View? CreateClass (Type type) { // If we are to create a generic Type if (type.IsGenericType) @@ -533,7 +518,7 @@ View CreateClass (Type type) } // Instantiate view - var view = (View)Activator.CreateInstance (type); + var view = Activator.CreateInstance (type) as View; if (view is null) { @@ -562,7 +547,7 @@ View CreateClass (Type type) } catch (TargetInvocationException e) { - MessageBox.ErrorQuery ("Exception", e.InnerException.Message, "Ok"); + MessageBox.ErrorQuery ("Exception", e.InnerException!.Message, "Ok"); view = null; } } @@ -570,7 +555,7 @@ View CreateClass (Type type) // If the view supports a Title property, set it so we have something to look at if (view != null && view.GetType ().GetProperty ("Title") != null) { - if (view.GetType ().GetProperty ("Title").PropertyType == typeof (string)) + if (view.GetType ().GetProperty ("Title")!.PropertyType == typeof (string)) { view?.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (view, new [] { "Test Title" }); } @@ -583,28 +568,28 @@ View CreateClass (Type type) // If the view supports a Source property, set it so we have something to look at if (view != null && view.GetType ().GetProperty ("Source") != null - && view.GetType ().GetProperty ("Source").PropertyType == typeof (IListDataSource)) + && view.GetType ().GetProperty ("Source")!.PropertyType == typeof (IListDataSource)) { ListWrapper source = new (["Test Text #1", "Test Text #2", "Test Text #3"]); view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source }); } // Add - _hostPane.Add (view); + hostPane.Add (view); //DimPosChanged (); - _hostPane.LayoutSubviews (); - _hostPane.ClearViewport (); - _hostPane.SetNeedsDraw (); - UpdateSettings (view); + hostPane.LayoutSubViews (); + hostPane.ClearViewport (); + hostPane.SetNeedsDraw (); + UpdateSettings (view!); UpdateTitle (view); - view.SubviewsLaidOut += LayoutCompleteHandler; + view!.SubViewsLaidOut += LayoutCompleteHandler; return view; } - void LayoutCompleteHandler (object sender, LayoutEventArgs args) { UpdateTitle (_curView); } + void LayoutCompleteHandler (object? sender, LayoutEventArgs args) { UpdateTitle (curView); } } [Fact] @@ -631,40 +616,37 @@ public void Run_Generic () var abortCount = 0; Func abortCallback = () => - { - abortCount++; - _output.WriteLine ($"'Generic' abortCount {abortCount}"); - Application.RequestStop (); + { + abortCount++; + _output.WriteLine ($"'Generic' abortCount {abortCount}"); + Application.RequestStop (); - return false; - }; + return false; + }; var iterations = 0; - object token = null; + object? token = null; Application.Iteration += (s, a) => - { - if (token == null) - { - // Timeout only must start at first iteration - token = Application.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback); - } - - iterations++; - _output.WriteLine ($"'Generic' iteration {iterations}"); - - // Stop if we run out of control... - if (iterations == 10) - { - _output.WriteLine ("'Generic' had to be force quit!"); - Application.RequestStop (); - } - }; - - Application.KeyDown += (sender, args) => - { - Assert.Equal (Application.QuitKey, args.KeyCode); - }; + { + if (token == null) + { + // Timeout only must start at first iteration + token = Application.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback); + } + + iterations++; + _output.WriteLine ($"'Generic' iteration {iterations}"); + + // Stop if we run out of control... + if (iterations == 10) + { + _output.WriteLine ("'Generic' had to be force quit!"); + Application.RequestStop (); + } + }; + + Application.KeyDown += (sender, args) => { Assert.Equal (Application.QuitKey, args.KeyCode); }; generic.Main (); @@ -686,30 +668,4 @@ public void Run_Generic () Assert.Empty (View.Instances); #endif } - - private int CreateInput (string input) - { - FakeConsole.MockKeyPresses.Clear (); - - // Put a QuitKey in at the end - FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey); - - foreach (char c in input.Reverse ()) - { - var key = KeyCode.Null; - - if (char.IsLetter (c)) - { - key = (KeyCode)char.ToUpper (c) | (char.IsUpper (c) ? KeyCode.ShiftMask : 0); - } - else - { - key = (KeyCode)c; - } - - FakeConsole.PushMockKeyPress (key); - } - - return FakeConsole.MockKeyPresses.Count; - } } diff --git a/Tests/StressTests/ApplicationStressTests.cs b/Tests/StressTests/ApplicationStressTests.cs index b326a054cf..bf1c525b0b 100644 --- a/Tests/StressTests/ApplicationStressTests.cs +++ b/Tests/StressTests/ApplicationStressTests.cs @@ -13,7 +13,13 @@ public ApplicationStressTests (ITestOutputHelper output) } private static volatile int _tbCounter; +#pragma warning disable IDE1006 // Naming Styles private static readonly ManualResetEventSlim _wakeUp = new (false); +#pragma warning restore IDE1006 // Naming Styles + + private const int NUM_PASSES = 50; + private const int NUM_INCREMENTS = 500; + private const int POLL_MS = 100; [Theory] [InlineData (typeof (FakeDriver))] @@ -30,9 +36,6 @@ public async Task InvokeLeakTest (Type driverType) var top = new Toplevel (); top.Add (tf); - const int NUM_PASSES = 50; - const int NUM_INCREMENTS = 500; - const int POLL_MS = 100; _tbCounter = 0; Task task = Task.Run (() => RunTest (r, tf, NUM_PASSES, NUM_INCREMENTS, POLL_MS)); diff --git a/Tests/StressTests/ScenariosStressTests.cs b/Tests/StressTests/ScenariosStressTests.cs index 007cd58b38..72ea6a7db0 100644 --- a/Tests/StressTests/ScenariosStressTests.cs +++ b/Tests/StressTests/ScenariosStressTests.cs @@ -150,19 +150,19 @@ void OnApplicationNotifyNewRunState (object? sender, RunStateEventArgs e) { // Get a list of all subviews under Application.Top (and their subviews, etc.) // and subscribe to their DrawComplete event - void SubscribeAllSubviews (View view) + void SubscribeAllSubViews (View view) { view.DrawComplete += (s, a) => drawCompleteCount++; - view.SubviewsLaidOut += (s, a) => laidOutCount++; - view.Added += (s, a) => addedCount++; + view.SubViewsLaidOut += (s, a) => laidOutCount++; + view.SuperViewChanged += (s, a) => addedCount++; - foreach (View subview in view.Subviews) + foreach (View subview in view.SubViews) { - SubscribeAllSubviews (subview); + SubscribeAllSubViews (subview); } } - SubscribeAllSubviews (Application.Top!); + SubscribeAllSubViews (Application.Top!); } // If the scenario doesn't close within the abort time, this will force it to quit diff --git a/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs b/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs index 1554ac65e3..0dcbda50b6 100644 --- a/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - +#nullable enable namespace UnitTests.ConsoleDrivers; + public class AnsiKeyboardParserTests { private readonly AnsiKeyboardParser _parser = new (); - public static IEnumerable GetKeyboardTestData () + public static IEnumerable GetKeyboardTestData () { // Test data for various ANSI escape sequences and their expected Key values yield return new object [] { "\u001b[A", Key.CursorUp }; @@ -50,19 +46,18 @@ public static IEnumerable GetKeyboardTestData () yield return new object [] { "\u001b[1;7D", Key.CursorLeft.WithCtrl.WithAlt }; yield return new object [] { "\u001b[1;8D", Key.CursorLeft.WithCtrl.WithAlt.WithShift }; - // Invalid inputs - yield return new object [] { "\u001b[Z", null }; - yield return new object [] { "\u001b[invalid", null }; - yield return new object [] { "\u001b[1", null }; - yield return new object [] { "\u001b[AB", null }; - yield return new object [] { "\u001b[;A", null }; + yield return new object [] { "\u001b[Z", null! }; + yield return new object [] { "\u001b[invalid", null! }; + yield return new object [] { "\u001b[1", null! }; + yield return new object [] { "\u001b[AB", null! }; + yield return new object [] { "\u001b[;A", null! }; } // Consolidated test for all keyboard events (e.g., arrow keys) [Theory] [MemberData (nameof (GetKeyboardTestData))] - public void ProcessKeyboardInput_ReturnsCorrectKey (string input, Key? expectedKey) + public void ProcessKeyboardInput_ReturnsCorrectKey (string? input, Key? expectedKey) { // Act Key? result = _parser.IsKeyboard (input)?.GetKey (input); diff --git a/Tests/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs b/Tests/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs index fcc2b6127d..9565d28b87 100644 --- a/Tests/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs @@ -1,39 +1,42 @@ -using System.Diagnostics; +#nullable enable +using System.Diagnostics; using System.Text; using Xunit.Abstractions; namespace UnitTests.ConsoleDrivers; + public class AnsiResponseParserTests (ITestOutputHelper output) { - AnsiResponseParser _parser1 = new AnsiResponseParser (); - AnsiResponseParser _parser2 = new AnsiResponseParser (); + private readonly AnsiResponseParser _parser1 = new (); + private readonly AnsiResponseParser _parser2 = new (); /// - /// Used for the T value in batches that are passed to the AnsiResponseParser<int> (parser1) + /// Used for the T value in batches that are passed to the AnsiResponseParser<int> (parser1) /// - private int tIndex = 0; + private int _tIndex; [Fact] public void TestInputProcessing () { - string ansiStream = "\u001b[<0;10;20M" + // ANSI escape for mouse move at (10, 20) - "Hello" + // User types "Hello" - "\u001b[0c"; // Device Attributes response (e.g., terminal identification i.e. DAR) - + string ansiStream = "\u001b[<0;10;20M" + + // ANSI escape for mouse move at (10, 20) + "Hello" + + // User types "Hello" + "\u001b[0c"; // Device Attributes response (e.g., terminal identification i.e. DAR) - string response1 = null; - string response2 = null; + string? response1 = null; + string? response2 = null; - int i = 0; + var i = 0; // Imagine that we are expecting a DAR - _parser1.ExpectResponse ("c",(s)=> response1 = s,null, false); - _parser2.ExpectResponse ("c", (s) => response2 = s , null, false); + _parser1.ExpectResponse ("c", s => response1 = s, null, false); + _parser2.ExpectResponse ("c", s => response2 = s, null, false); // First char is Escape which we must consume incase what follows is the DAR AssertConsumed (ansiStream, ref i); // Esc - for (int c = 0; c < "[<0;10;20".Length; c++) + for (var c = 0; c < "[<0;10;20".Length; c++) { AssertConsumed (ansiStream, ref i); } @@ -42,13 +45,13 @@ public void TestInputProcessing () AssertReleased (ansiStream, ref i, "\u001b[<0;10;20M"); // Regular user typing - for (int c = 0; c < "Hello".Length; c++) + for (var c = 0; c < "Hello".Length; c++) { - AssertIgnored (ansiStream,"Hello"[c], ref i); + AssertIgnored (ansiStream, "Hello" [c], ref i); } // Now we have entered the actual DAR we should be consuming these - for (int c = 0; c < "\u001b[0".Length; c++) + for (var c = 0; c < "\u001b[0".Length; c++) { AssertConsumed (ansiStream, ref i); } @@ -69,7 +72,7 @@ public void TestInputProcessing () [InlineData ("\u001b[0cHi\u001b[0c", "c", "\u001b[0c", "Hi\u001b[0c")] [InlineData ("\u001b[<0;0;0MHe\u001b[3c", "c", "\u001b[3c", "\u001b[<0;0;0MHe")] [InlineData ("\u001b[<0;1;2Da\u001b[0c\u001b[1c", "c", "\u001b[0c", "\u001b[<0;1;2Da\u001b[1c")] - [InlineData ("\u001b[1;1M\u001b[3cAn", "c", "\u001b[3c", "\u001b[1;1MAn")] + [InlineData ("\u001b[1;1M\u001b[3cAn", "c", "\u001b[3c", "\u001b[1;1MAn")] [InlineData ("hi\u001b[2c\u001b[<5;5;5m", "c", "\u001b[2c", "hi\u001b[<5;5;5m")] [InlineData ("\u001b[3c\u001b[4c\u001b[<0;0;0MIn", "c", "\u001b[3c", "\u001b[4c\u001b[<0;0;0MIn")] [InlineData ("\u001b[<1;2;3M\u001b[0c\u001b[<1;2;3M\u001b[2c", "c", "\u001b[0c", "\u001b[<1;2;3M\u001b[<1;2;3M\u001b[2c")] @@ -84,8 +87,16 @@ public void TestInputProcessing () [InlineData ("\u001b[<1;1;1MJJ\u001b[9c", "c", "\u001b[9c", "\u001b[<1;1;1MJJ")] // Mixed text [InlineData ("Be\u001b[0cAf", "c", "\u001b[0c", "BeAf")] // Escape in the middle of the string [InlineData ("\u001b[<0;0;0M\u001b[2cNot e", "c", "\u001b[2c", "\u001b[<0;0;0MNot e")] // Unexpected sequence followed by text - [InlineData ("Just te\u001b[<0;0;0M\u001b[3c\u001b[2c\u001b[4c", "c", "\u001b[3c", "Just te\u001b[<0;0;0M\u001b[2c\u001b[4c")] // Multiple unexpected responses - [InlineData ("\u001b[1;2;3M\u001b[0c\u001b[2;2M\u001b[0;0;0MTe", "c", "\u001b[0c", "\u001b[1;2;3M\u001b[2;2M\u001b[0;0;0MTe")] // Multiple commands with responses + [InlineData ( + "Just te\u001b[<0;0;0M\u001b[3c\u001b[2c\u001b[4c", + "c", + "\u001b[3c", + "Just te\u001b[<0;0;0M\u001b[2c\u001b[4c")] // Multiple unexpected responses + [InlineData ( + "\u001b[1;2;3M\u001b[0c\u001b[2;2M\u001b[0;0;0MTe", + "c", + "\u001b[0c", + "\u001b[1;2;3M\u001b[2;2M\u001b[0;0;0MTe")] // Multiple commands with responses [InlineData ("\u001b[<3;3;3Mabc\u001b[4cde", "c", "\u001b[4c", "\u001b[<3;3;3Mabcde")] // Escape sequences mixed with regular text // Edge cases @@ -94,58 +105,57 @@ public void TestInputProcessing () [InlineData ("Normal", "c", "", "Normal")] // No escape sequences [InlineData ("\u001b[<0;0;0M", "c", "", "\u001b[<0;0;0M")] // Escape sequence only [InlineData ("\u001b[1;2;3M\u001b[0c", "c", "\u001b[0c", "\u001b[1;2;3M")] // Last response consumed - [InlineData ("Inpu\u001b[0c\u001b[1;0;0M", "c", "\u001b[0c", "Inpu\u001b[1;0;0M")] // Single input followed by escape [InlineData ("\u001b[2c\u001b[<5;6;7MDa", "c", "\u001b[2c", "\u001b[<5;6;7MDa")] // Multiple escape sequences followed by text [InlineData ("\u001b[0cHi\u001b[1cGo", "c", "\u001b[0c", "Hi\u001b[1cGo")] // Normal text with multiple escape sequences - [InlineData ("\u001b[<1;1;1MTe", "c", "", "\u001b[<1;1;1MTe")] + // Add more test cases here... - public void TestInputSequences (string ansiStream, string expectedTerminator, string expectedResponse, string expectedOutput) + public void TestInputSequences (string ansiStream, string? expectedTerminator, string expectedResponse, string expectedOutput) { var swGenBatches = Stopwatch.StartNew (); - int tests = 0; + var tests = 0; - var permutations = GetBatchPermutations (ansiStream,5).ToArray (); + string [] [] permutations = GetBatchPermutations (ansiStream, 5).ToArray (); swGenBatches.Stop (); var swRunTest = Stopwatch.StartNew (); - foreach (var batchSet in permutations) + foreach (string [] batchSet in permutations) { - tIndex = 0; - string response1 = string.Empty; - string response2 = string.Empty; + _tIndex = 0; + var response1 = string.Empty; + var response2 = string.Empty; // Register the expected response with the given terminator _parser1.ExpectResponse (expectedTerminator, s => response1 = s, null, false); _parser2.ExpectResponse (expectedTerminator, s => response2 = s, null, false); // Process the input - StringBuilder actualOutput1 = new StringBuilder (); - StringBuilder actualOutput2 = new StringBuilder (); + var actualOutput1 = new StringBuilder (); + var actualOutput2 = new StringBuilder (); - foreach (var batch in batchSet) + foreach (string batch in batchSet) { - var output1 = _parser1.ProcessInput (StringToBatch (batch)); + IEnumerable> output1 = _parser1.ProcessInput (StringToBatch (batch)); actualOutput1.Append (BatchToString (output1)); - var output2 = _parser2.ProcessInput (batch); + string output2 = _parser2.ProcessInput (batch); actualOutput2.Append (output2); } // Assert the final output minus the expected response - Assert.Equal (expectedOutput, actualOutput1.ToString()); + Assert.Equal (expectedOutput, actualOutput1.ToString ()); Assert.Equal (expectedResponse, response1); Assert.Equal (expectedOutput, actualOutput2.ToString ()); Assert.Equal (expectedResponse, response2); tests++; } - output.WriteLine ($"Tested {tests} in {swRunTest.ElapsedMilliseconds} ms (gen batches took {swGenBatches.ElapsedMilliseconds} ms)" ); + output.WriteLine ($"Tested {tests} in {swRunTest.ElapsedMilliseconds} ms (gen batches took {swGenBatches.ElapsedMilliseconds} ms)"); } - public static IEnumerable TestInputSequencesExact_Cases () + public static IEnumerable TestInputSequencesExact_Cases () { yield return [ @@ -153,7 +163,7 @@ public static IEnumerable TestInputSequencesExact_Cases () null, new [] { - new StepExpectation ('\u001b',AnsiResponseParserState.ExpectingEscapeSequence,string.Empty) + new StepExpectation ('\u001b', AnsiResponseParserState.ExpectingEscapeSequence, string.Empty) } ]; @@ -163,13 +173,20 @@ public static IEnumerable TestInputSequencesExact_Cases () 'c', new [] { - new StepExpectation ('\u001b',AnsiResponseParserState.ExpectingEscapeSequence,string.Empty), - new StepExpectation ('H',AnsiResponseParserState.InResponse,string.Empty), // H is known terminator and not expected one so here we release both chars - new StepExpectation ('\u001b',AnsiResponseParserState.ExpectingEscapeSequence,"\u001bH"), - new StepExpectation ('[',AnsiResponseParserState.InResponse,string.Empty), - new StepExpectation ('0',AnsiResponseParserState.InResponse,string.Empty), - new StepExpectation ('c',AnsiResponseParserState.Normal,string.Empty,"\u001b[0c"), // c is expected terminator so here we swallow input and populate expected response - new StepExpectation ('\u001b',AnsiResponseParserState.ExpectingEscapeSequence,string.Empty), + new StepExpectation ('\u001b', AnsiResponseParserState.ExpectingEscapeSequence, string.Empty), + new StepExpectation ( + 'H', + AnsiResponseParserState.InResponse, + string.Empty), // H is known terminator and not expected one so here we release both chars + new StepExpectation ('\u001b', AnsiResponseParserState.ExpectingEscapeSequence, "\u001bH"), + new StepExpectation ('[', AnsiResponseParserState.InResponse, string.Empty), + new StepExpectation ('0', AnsiResponseParserState.InResponse, string.Empty), + new StepExpectation ( + 'c', + AnsiResponseParserState.Normal, + string.Empty, + "\u001b[0c"), // c is expected terminator so here we swallow input and populate expected response + new StepExpectation ('\u001b', AnsiResponseParserState.ExpectingEscapeSequence, string.Empty) } ]; } @@ -177,24 +194,24 @@ public static IEnumerable TestInputSequencesExact_Cases () public class StepExpectation () { /// - /// The input character to feed into the parser at this step of the test + /// The input character to feed into the parser at this step of the test /// public char Input { get; } /// - /// What should the state of the parser be after the - /// is fed in. + /// What should the state of the parser be after the + /// is fed in. /// public AnsiResponseParserState ExpectedStateAfterOperation { get; } /// - /// If this step should release one or more characters, put them here. + /// If this step should release one or more characters, put them here. /// public string ExpectedRelease { get; } = string.Empty; /// - /// If this step should result in a completing of detection of ANSI response - /// then put the expected full response sequence here. + /// If this step should result in a completing of detection of ANSI response + /// then put the expected full response sequence here. /// public string ExpectedAnsiResponse { get; } = string.Empty; @@ -202,35 +219,36 @@ public StepExpectation ( char input, AnsiResponseParserState expectedStateAfterOperation, string expectedRelease = "", - string expectedAnsiResponse = "") : this () + string expectedAnsiResponse = "" + ) : this () { Input = input; ExpectedStateAfterOperation = expectedStateAfterOperation; ExpectedRelease = expectedRelease; ExpectedAnsiResponse = expectedAnsiResponse; } - } - - - [MemberData(nameof(TestInputSequencesExact_Cases))] + [MemberData (nameof (TestInputSequencesExact_Cases))] [Theory] public void TestInputSequencesExact (string caseName, char? terminator, IEnumerable expectedStates) { output.WriteLine ("Running test case:" + caseName); var parser = new AnsiResponseParser (); - string response = null; + string? response = null; if (terminator.HasValue) { - parser.ExpectResponse (terminator.Value.ToString (),(s)=> response = s,null, false); + parser.ExpectResponse (terminator.Value.ToString (), s => response = s, null, false); } - int step= 0; - foreach (var state in expectedStates) + + var step = 0; + + foreach (StepExpectation state in expectedStates) { step++; + // If we expect the response to be detected at this step if (!string.IsNullOrWhiteSpace (state.ExpectedAnsiResponse)) { @@ -238,9 +256,9 @@ public void TestInputSequencesExact (string caseName, char? terminator, IEnumera Assert.Null (response); } - var actual = parser.ProcessInput (state.Input.ToString ()); + string actual = parser.ProcessInput (state.Input.ToString ()); - Assert.Equal (state.ExpectedRelease,actual); + Assert.Equal (state.ExpectedRelease, actual); Assert.Equal (state.ExpectedStateAfterOperation, parser.State); // If we expect the response to be detected at this step @@ -257,11 +275,11 @@ public void TestInputSequencesExact (string caseName, char? terminator, IEnumera [Fact] public void ReleasesEscapeAfterTimeout () { - string input = "\u001b"; - int i = 0; + var input = "\u001b"; + var i = 0; // Esc on its own looks like it might be an esc sequence so should be consumed - AssertConsumed (input,ref i); + AssertConsumed (input, ref i); // We should know when the state changed Assert.Equal (AnsiResponseParserState.ExpectingEscapeSequence, _parser1.State); @@ -273,24 +291,23 @@ public void ReleasesEscapeAfterTimeout () AssertManualReleaseIs (input); } - [Fact] - public void TwoExcapesInARow () + public void TwoEscapesInARow () { // Example user presses Esc key then a DAR comes in - string input = "\u001b\u001b"; - int i = 0; + var input = "\u001b\u001b"; + var i = 0; // First Esc gets grabbed AssertConsumed (input, ref i); // Upon getting the second Esc we should release the first - AssertReleased (input, ref i, "\u001b",0); + AssertReleased (input, ref i, "\u001b", 0); // Assume 50ms or something has passed, lets force release as no new content // It should be the second escape that gets released (i.e. index 1) - AssertManualReleaseIs ("\u001b",1); + AssertManualReleaseIs ("\u001b", 1); } [Fact] @@ -298,19 +315,19 @@ public void TestLateResponses () { var p = new AnsiResponseParser (); - string responseA = null; - string responseB = null; + string? responseA = null; + string? responseB = null; - p.ExpectResponse ("z",(r)=>responseA=r, null, false); + p.ExpectResponse ("z", r => responseA = r, null, false); // Some time goes by without us seeing a response p.StopExpecting ("z", false); // Send our new request - p.ExpectResponse ("z", (r) => responseB = r, null, false); + p.ExpectResponse ("z", r => responseB = r, null, false); // Because we gave up on getting A, we should expect the response to be to our new request - Assert.Empty(p.ProcessInput ("\u001b[<1;2z")); + Assert.Empty (p.ProcessInput ("\u001b[<1;2z")); Assert.Null (responseA); Assert.Equal ("\u001b[<1;2z", responseB); @@ -323,7 +340,6 @@ public void TestLateResponses () // We now have no outstanding requests (late or otherwise) so new ansi codes should just fall through Assert.Equal ("\u001b[111z", p.ProcessInput ("\u001b[111z")); - } [Fact] @@ -331,57 +347,61 @@ public void TestPersistentResponses () { var p = new AnsiResponseParser (); - int m = 0; - int M = 1; + var m = 0; + var M = 1; p.ExpectResponse ("m", _ => m++, null, true); p.ExpectResponse ("M", _ => M++, null, true); // Act - Feed input strings containing ANSI sequences - p.ProcessInput ("\u001b[<0;10;10m"); // Should match and increment `m` - p.ProcessInput ("\u001b[<0;20;20m"); // Should match and increment `m` - p.ProcessInput ("\u001b[<0;30;30M"); // Should match and increment `M` - p.ProcessInput ("\u001b[<0;40;40M"); // Should match and increment `M` - p.ProcessInput ("\u001b[<0;50;50M"); // Should match and increment `M` + p.ProcessInput ("\u001b[<0;10;10m"); // Should match and increment `m` + p.ProcessInput ("\u001b[<0;20;20m"); // Should match and increment `m` + p.ProcessInput ("\u001b[<0;30;30M"); // Should match and increment `M` + p.ProcessInput ("\u001b[<0;40;40M"); // Should match and increment `M` + p.ProcessInput ("\u001b[<0;50;50M"); // Should match and increment `M` // Assert - Verify that counters reflect the expected counts of each terminator - Assert.Equal (2, m); // Expected two `m` responses - Assert.Equal (4, M); // Expected three `M` responses plus the initial value of 1 + Assert.Equal (2, m); // Expected two `m` responses + Assert.Equal (4, M); // Expected three `M` responses plus the initial value of 1 } [Fact] public void TestPersistentResponses_WithMetadata () { - var p = new AnsiResponseParser (); + AnsiResponseParser p = new (); - int m = 0; + // ReSharper disable once NotAccessedVariable + var m = 0; - var result = new List> (); + List> result = new (); - p.ExpectResponseT ("m", (r) => - { - result = r.ToList (); - m++; - }, - null, true); + p.ExpectResponseT ( + "m", + r => + { + result = r.ToList (); + m++; + }, + null, + true); // Act - Feed input strings containing ANSI sequences - p.ProcessInput (StringToBatch("\u001b[<0;10;10m")); // Should match and increment `m` + p.ProcessInput (StringToBatch ("\u001b[<0;10;10m")); // Should match and increment `m` // Prepare expected result: - var expected = new List> + List> expected = new() { - Tuple.Create('\u001b', 0), // Escape character - Tuple.Create('[', 1), - Tuple.Create('<', 2), - Tuple.Create('0', 3), - Tuple.Create(';', 4), - Tuple.Create('1', 5), - Tuple.Create('0', 6), - Tuple.Create(';', 7), - Tuple.Create('1', 8), - Tuple.Create('0', 9), - Tuple.Create('m', 10) + Tuple.Create ('\u001b', 0), // Escape character + Tuple.Create ('[', 1), + Tuple.Create ('<', 2), + Tuple.Create ('0', 3), + Tuple.Create (';', 4), + Tuple.Create ('1', 5), + Tuple.Create ('0', 6), + Tuple.Create (';', 7), + Tuple.Create ('1', 8), + Tuple.Create ('0', 9), + Tuple.Create ('m', 10) }; Assert.Equal (expected.Count, result.Count); // Ensure the count is as expected @@ -395,7 +415,6 @@ public void ShouldSwallowUnknownResponses_WhenDelegateSaysSo () _parser1.UnexpectedResponseHandler = _ => true; _parser2.UnknownResponseHandler = _ => true; - AssertReleased ( "Just te\u001b[<0;0;0M\u001b[3c\u001b[2c\u001b[4cst", "Just test", @@ -414,19 +433,21 @@ public void ShouldSwallowUnknownResponses_WhenDelegateSaysSo () public void UnknownResponses_ParameterShouldMatch () { // Track unknown responses passed to the UnexpectedResponseHandler - var unknownResponses = new List (); + List unknownResponses = new (); // Set up the UnexpectedResponseHandler to log each unknown response _parser1.UnexpectedResponseHandler = r1 => - { - unknownResponses.Add (BatchToString (r1)); - return true; // Return true to swallow unknown responses - }; + { + unknownResponses.Add (BatchToString (r1)); + + return true; // Return true to swallow unknown responses + }; _parser2.UnknownResponseHandler = r2 => { // parsers should be agreeing on what these responses are! - Assert.Equal(unknownResponses.Last(),r2); + Assert.Equal (unknownResponses.Last (), r2); + return true; // Return true to swallow unknown responses }; @@ -436,7 +457,7 @@ public void UnknownResponses_ParameterShouldMatch () "Just test"); // Expected unknown responses (ANSI sequences that are unknown) - var expectedUnknownResponses = new List + List expectedUnknownResponses = new() { "\u001b[<0;0;0M", "\u001b[3c", @@ -468,19 +489,20 @@ public void ParserDetectsMouse () List mouseEventArgs = new (); parser.Mouse += (s, e) => mouseEventArgs.Add (e); - parser.ExpectResponse ("c", (dar) => foundDar = dar, null, false); - var released = parser.ProcessInput ("a" + MOUSE_DOWN + "asdf" + DEVICE_ATTRIBUTE_RESPONSE + "bbcc" + MOUSE_UP + "sss"); + parser.ExpectResponse ("c", dar => foundDar = dar, null, false); + string released = parser.ProcessInput ("a" + MOUSE_DOWN + "asdf" + DEVICE_ATTRIBUTE_RESPONSE + "bbcc" + MOUSE_UP + "sss"); Assert.Equal ("aasdfbbccsss", released); Assert.Equal (2, mouseEventArgs.Count); Assert.NotNull (foundDar); - Assert.Equal (DEVICE_ATTRIBUTE_RESPONSE,foundDar); + Assert.Equal (DEVICE_ATTRIBUTE_RESPONSE, foundDar); Assert.True (mouseEventArgs [0].IsPressed); + // Mouse positions in ANSI are 1 based so actual Terminal.Gui Screen positions are x-1,y-1 - Assert.Equal (11,mouseEventArgs [0].Position.X); + Assert.Equal (11, mouseEventArgs [0].Position.X); Assert.Equal (31, mouseEventArgs [0].Position.Y); Assert.True (mouseEventArgs [1].IsReleased); @@ -488,11 +510,9 @@ public void ParserDetectsMouse () Assert.Equal (49, mouseEventArgs [1].Position.Y); } - [Fact] public void ParserDetectsKeyboard () { - // ANSI escape sequence for cursor left const string LEFT = "\u001b[D"; @@ -509,8 +529,8 @@ public void ParserDetectsKeyboard () List keys = new (); parser.Keyboard += (s, e) => keys.Add (e); - parser.ExpectResponse ("c", (dar) => foundDar = dar, null, false); - var released = parser.ProcessInput ("a" + LEFT + "asdf" + DEVICE_ATTRIBUTE_RESPONSE + "bbcc" + SHIFT_UP + "sss"); + parser.ExpectResponse ("c", dar => foundDar = dar, null, false); + string released = parser.ProcessInput ("a" + LEFT + "asdf" + DEVICE_ATTRIBUTE_RESPONSE + "bbcc" + SHIFT_UP + "sss"); Assert.Equal ("aasdfbbccsss", released); @@ -519,7 +539,7 @@ public void ParserDetectsKeyboard () Assert.NotNull (foundDar); Assert.Equal (DEVICE_ATTRIBUTE_RESPONSE, foundDar); - Assert.Equal (Key.CursorLeft,keys [0]); + Assert.Equal (Key.CursorLeft, keys [0]); Assert.Equal (Key.CursorUp.WithShift, keys [1]); } @@ -550,71 +570,81 @@ public static IEnumerable ParserDetects_FunctionKeys_Cases () Key.F4 ]; - // These are also F keys - yield return [ - "\u001b[11~", - Key.F1 - ]; - - yield return [ - "\u001b[12~", - Key.F2 - ]; - - yield return [ - "\u001b[13~", - Key.F3 - ]; - - yield return [ - "\u001b[14~", - Key.F4 - ]; - - yield return [ - "\u001b[15~", - Key.F5 - ]; - - yield return [ - "\u001b[17~", - Key.F6 - ]; - - yield return [ - "\u001b[18~", - Key.F7 - ]; - - yield return [ - "\u001b[19~", - Key.F8 - ]; - - yield return [ - "\u001b[20~", - Key.F9 - ]; - - yield return [ - "\u001b[21~", - Key.F10 - ]; - - yield return [ - "\u001b[23~", - Key.F11 - ]; - - yield return [ - "\u001b[24~", - Key.F12 - ]; + yield return + [ + "\u001b[11~", + Key.F1 + ]; + + yield return + [ + "\u001b[12~", + Key.F2 + ]; + + yield return + [ + "\u001b[13~", + Key.F3 + ]; + + yield return + [ + "\u001b[14~", + Key.F4 + ]; + + yield return + [ + "\u001b[15~", + Key.F5 + ]; + + yield return + [ + "\u001b[17~", + Key.F6 + ]; + + yield return + [ + "\u001b[18~", + Key.F7 + ]; + + yield return + [ + "\u001b[19~", + Key.F8 + ]; + + yield return + [ + "\u001b[20~", + Key.F9 + ]; + + yield return + [ + "\u001b[21~", + Key.F10 + ]; + + yield return + [ + "\u001b[23~", + Key.F11 + ]; + + yield return + [ + "\u001b[24~", + Key.F12 + ]; } [MemberData (nameof (ParserDetects_FunctionKeys_Cases))] - [Theory] public void ParserDetects_FunctionKeys (string input, Key expectedKey) { @@ -625,20 +655,18 @@ public void ParserDetects_FunctionKeys (string input, Key expectedKey) parser.Keyboard += (s, e) => keys.Add (e); - foreach (var ch in input.ToCharArray ()) + foreach (char ch in input) { - parser.ProcessInput (new (ch,1)); + parser.ProcessInput (new (ch, 1)); } - var k = Assert.Single (keys); - Assert.Equal (k,expectedKey); - } + Key k = Assert.Single (keys); - private Tuple [] StringToBatch (string batch) - { - return batch.Select ((k) => Tuple.Create (k, tIndex++)).ToArray (); + Assert.Equal (k, expectedKey); } + private Tuple [] StringToBatch (string batch) { return batch.Select (k => Tuple.Create (k, _tIndex++)).ToArray (); } + public static IEnumerable GetBatchPermutations (string input, int maxDepth = 3) { // Call the recursive method to generate batches with an initial depth of 0 @@ -657,6 +685,7 @@ private static IEnumerable GenerateBatches (string input, int start, if (start >= input.Length) { yield return new string [0]; + yield break; } @@ -667,42 +696,44 @@ private static IEnumerable GenerateBatches (string input, int start, string batch = input.Substring (start, i - start); // Recursively get batches from the remaining substring, increasing the depth - foreach (var remainingBatches in GenerateBatches (input, i, maxDepth, currentDepth + 1)) + foreach (string [] remainingBatches in GenerateBatches (input, i, maxDepth, currentDepth + 1)) { // Combine the current batch with the remaining batches var result = new string [1 + remainingBatches.Length]; result [0] = batch; Array.Copy (remainingBatches, 0, result, 1, remainingBatches.Length); + yield return result; } } } - private void AssertIgnored (string ansiStream,char expected, ref int i) + private void AssertIgnored (string ansiStream, char expected, ref int i) { - var c2 = ansiStream [i]; - var c1 = NextChar (ansiStream, ref i); + char c2 = ansiStream [i]; + Tuple [] c1 = NextChar (ansiStream, ref i); // Parser does not grab this key (i.e. driver can continue with regular operations) - Assert.Equal ( c1,_parser1.ProcessInput (c1)); - Assert.Equal (expected,c1.Single().Item1); + Assert.Equal (c1, _parser1.ProcessInput (c1)); + Assert.Equal (expected, c1.Single ().Item1); - Assert.Equal (c2, _parser2.ProcessInput (c2.ToString()).Single()); - Assert.Equal (expected, c2 ); + Assert.Equal (c2, _parser2.ProcessInput (c2.ToString ()).Single ()); + Assert.Equal (expected, c2); } + private void AssertConsumed (string ansiStream, ref int i) { // Parser grabs this key - var c2 = ansiStream [i]; - var c1 = NextChar (ansiStream, ref i); + char c2 = ansiStream [i]; + Tuple [] c1 = NextChar (ansiStream, ref i); - Assert.Empty (_parser1.ProcessInput(c1)); - Assert.Empty (_parser2.ProcessInput (c2.ToString())); + Assert.Empty (_parser1.ProcessInput (c1)); + Assert.Empty (_parser2.ProcessInput (c2.ToString ())); } /// - /// Overload that fully exhausts and asserts - /// that the final released content across whole processing is + /// Overload that fully exhausts and asserts + /// that the final released content across whole processing is /// /// /// @@ -710,28 +741,27 @@ private void AssertConsumed (string ansiStream, ref int i) private void AssertReleased (string ansiStream, string expectedRelease, params int [] expectedTValues) { var sb = new StringBuilder (); - var tValues = new List (); + List tValues = new (); - int i = 0; + var i = 0; while (i < ansiStream.Length) { - var c2 = ansiStream [i]; - var c1 = NextChar (ansiStream, ref i); + char c2 = ansiStream [i]; + Tuple [] c1 = NextChar (ansiStream, ref i); - var released1 = _parser1.ProcessInput (c1).ToArray (); - tValues.AddRange(released1.Select (kv => kv.Item2)); + Tuple [] released1 = _parser1.ProcessInput (c1).ToArray (); + tValues.AddRange (released1.Select (kv => kv.Item2)); - - var released2 = _parser2.ProcessInput (c2.ToString ()); + string released2 = _parser2.ProcessInput (c2.ToString ()); // Both parsers should have same chars so release chars consistently with each other - Assert.Equal (BatchToString(released1),released2); + Assert.Equal (BatchToString (released1), released2); sb.Append (released2); } - Assert.Equal (expectedRelease, sb.ToString()); + Assert.Equal (expectedRelease, sb.ToString ()); if (expectedTValues.Length > 0) { @@ -740,46 +770,40 @@ private void AssertReleased (string ansiStream, string expectedRelease, params i } /// - /// Asserts that index of when consumed will release - /// . Results in implicit increment of . - /// Note that this does NOT iteratively consume all the stream, only 1 char at + /// Asserts that index of when consumed will release + /// . Results in implicit increment of . + /// Note that this does NOT iteratively consume all the stream, only 1 char at /// /// /// /// /// - private void AssertReleased (string ansiStream, ref int i, string expectedRelease, params int[] expectedTValues) + private void AssertReleased (string ansiStream, ref int i, string expectedRelease, params int [] expectedTValues) { - var c2 = ansiStream [i]; - var c1 = NextChar (ansiStream, ref i); + char c2 = ansiStream [i]; + Tuple [] c1 = NextChar (ansiStream, ref i); // Parser realizes it has grabbed content that does not belong to an outstanding request // Parser returns false to indicate to continue - var released1 = _parser1.ProcessInput (c1).ToArray (); + Tuple [] released1 = _parser1.ProcessInput (c1).ToArray (); Assert.Equal (expectedRelease, BatchToString (released1)); if (expectedTValues.Length > 0) { - Assert.True (expectedTValues.SequenceEqual (released1.Select (kv=>kv.Item2))); + Assert.True (expectedTValues.SequenceEqual (released1.Select (kv => kv.Item2))); } Assert.Equal (expectedRelease, _parser2.ProcessInput (c2.ToString ())); } - private string BatchToString (IEnumerable> processInput) - { - return new string(processInput.Select (a=>a.Item1).ToArray ()); - } + private string BatchToString (IEnumerable> processInput) { return new (processInput.Select (a => a.Item1).ToArray ()); } + + private Tuple [] NextChar (string ansiStream, ref int i) { return StringToBatch (ansiStream [i++].ToString ()); } - private Tuple[] NextChar (string ansiStream, ref int i) - { - return StringToBatch(ansiStream [i++].ToString()); - } private void AssertManualReleaseIs (string expectedRelease, params int [] expectedTValues) { - // Consumer is responsible for determining this based on e.g. after 50ms - var released1 = _parser1.Release ().ToArray (); + Tuple [] released1 = _parser1.Release ().ToArray (); Assert.Equal (expectedRelease, BatchToString (released1)); if (expectedTValues.Length > 0) diff --git a/Tests/UnitTests/ConsoleDrivers/ContentsTests.cs b/Tests/UnitTests/ConsoleDrivers/ContentsTests.cs index 577ac2062c..cac50efecb 100644 --- a/Tests/UnitTests/ConsoleDrivers/ContentsTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/ContentsTests.cs @@ -1,6 +1,5 @@ using System.Text; using UnitTests; -using UnitTests; using Xunit.Abstractions; // Alias Console to MockConsole so we don't accidentally use Console @@ -9,12 +8,12 @@ namespace Terminal.Gui.DriverTests; public class ContentsTests { - private readonly ITestOutputHelper output; + private readonly ITestOutputHelper _output; public ContentsTests (ITestOutputHelper output) { ConsoleDriver.RunningUnitTests = true; - this.output = output; + _output = output; } [Theory] @@ -27,10 +26,10 @@ public ContentsTests (ITestOutputHelper output) public void AddStr_Combining_Character_1st_Column (Type driverType) { var driver = (IConsoleDriver)Activator.CreateInstance (driverType); - driver.Init (); + driver!.Init (); var expected = "\u0301!"; driver.AddStr ("\u0301!"); // acute accent + exclamation mark - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); driver.End (); } @@ -45,48 +44,48 @@ public void AddStr_Combining_Character_1st_Column (Type driverType) public void AddStr_With_Combining_Characters (Type driverType) { var driver = (IConsoleDriver)Activator.CreateInstance (driverType); - driver.Init (); + driver!.Init (); - var acuteaccent = new Rune (0x0301); // Combining acute accent (é) - string combined = "e" + acuteaccent; + var acuteAccent = new Rune (0x0301); // Combining acute accent (é) + string combined = "e" + acuteAccent; var expected = "é"; driver.AddStr (combined); - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); // 3 char combine // a + ogonek + acute = ( ą́ ) - var ogonek = new Rune (0x0328); // Combining ogonek (a small hook or comma shape) - combined = "a" + ogonek + acuteaccent; - expected = ("a" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616 + var oGonek = new Rune (0x0328); // Combining ogonek (a small hook or comma shape) + combined = "a" + oGonek + acuteAccent; + expected = ("a" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616 driver.Move (0, 0); driver.AddStr (combined); - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); // e + ogonek + acute = ( ę́́ ) - combined = "e" + ogonek + acuteaccent; - expected = ("e" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616 + combined = "e" + oGonek + acuteAccent; + expected = ("e" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616 driver.Move (0, 0); driver.AddStr (combined); - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); // i + ogonek + acute = ( į́́́ ) - combined = "i" + ogonek + acuteaccent; - expected = ("i" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616 + combined = "i" + oGonek + acuteAccent; + expected = ("i" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616 driver.Move (0, 0); driver.AddStr (combined); - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); // u + ogonek + acute = ( ų́́́́ ) - combined = "u" + ogonek + acuteaccent; - expected = ("u" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616 + combined = "u" + oGonek + acuteAccent; + expected = ("u" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616 driver.Move (0, 0); driver.AddStr (combined); - DriverAssert.AssertDriverContentsAre (expected, output, driver); + DriverAssert.AssertDriverContentsAre (expected, _output, driver); driver.End (); } diff --git a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs index 5500007780..1a87b6b593 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs @@ -1,4 +1,5 @@ -using System.Collections.Concurrent; +#nullable enable +using System.Collections.Concurrent; using Microsoft.Extensions.Logging; using Moq; @@ -298,7 +299,7 @@ public void TestRepeatedShutdownCalls_DoNotDuplicateDisposeOutput () v2.Shutdown (); v2.Shutdown (); - outputMock.Verify(o=>o.Dispose (),Times.Once); + outputMock!.Verify(o=>o.Dispose (),Times.Once); } [Fact] public void TestRepeatedInitCalls_WarnsAndIgnores () @@ -322,7 +323,7 @@ public void TestRepeatedInitCalls_WarnsAndIgnores () It.IsAny (), It.Is ((v, t) => v.ToString () == "Init called multiple times without shutdown, ignoring."), It.IsAny (), - It.IsAny> ()) + It.IsAny> ()!) ,Times.Exactly (2)); v2.Shutdown (); diff --git a/Tests/UnitTests/ConsoleDrivers/V2/WindowsInputProcessorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/WindowsInputProcessorTests.cs index 7c9fc14429..4103ff4cec 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/WindowsInputProcessorTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/WindowsInputProcessorTests.cs @@ -5,67 +5,74 @@ using MouseEventRecord = Terminal.Gui.WindowsConsole.MouseEventRecord; namespace UnitTests.ConsoleDrivers.V2; + public class WindowsInputProcessorTests { - [Fact] public void Test_ProcessQueue_CapitalHLowerE () { - var queue = new ConcurrentQueue (); - - queue.Enqueue (new InputRecord() - { - EventType = WindowsConsole.EventType.Key, - KeyEvent = new WindowsConsole.KeyEventRecord () - { - bKeyDown = true, - UnicodeChar = 'H', - dwControlKeyState = WindowsConsole.ControlKeyState.CapslockOn, - wVirtualKeyCode = (ConsoleKeyMapping.VK)72, - wVirtualScanCode = 35 - } - }); - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Key, - KeyEvent = new WindowsConsole.KeyEventRecord () - { - bKeyDown = false, - UnicodeChar = 'H', - dwControlKeyState = WindowsConsole.ControlKeyState.CapslockOn, - wVirtualKeyCode = (ConsoleKeyMapping.VK)72, - wVirtualScanCode = 35 - } - }); - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Key, - KeyEvent = new WindowsConsole.KeyEventRecord () - { - bKeyDown = true, - UnicodeChar = 'i', - dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - wVirtualKeyCode = (ConsoleKeyMapping.VK)73, - wVirtualScanCode = 23 - } - }); - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Key, - KeyEvent = new WindowsConsole.KeyEventRecord () - { - bKeyDown = false, - UnicodeChar = 'i', - dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - wVirtualKeyCode = (ConsoleKeyMapping.VK)73, - wVirtualScanCode = 23 - } - }); + ConcurrentQueue queue = new (); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Key, + KeyEvent = new() + { + bKeyDown = true, + UnicodeChar = 'H', + dwControlKeyState = WindowsConsole.ControlKeyState.CapslockOn, + wVirtualKeyCode = (ConsoleKeyMapping.VK)72, + wVirtualScanCode = 35 + } + }); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Key, + KeyEvent = new() + { + bKeyDown = false, + UnicodeChar = 'H', + dwControlKeyState = WindowsConsole.ControlKeyState.CapslockOn, + wVirtualKeyCode = (ConsoleKeyMapping.VK)72, + wVirtualScanCode = 35 + } + }); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Key, + KeyEvent = new() + { + bKeyDown = true, + UnicodeChar = 'i', + dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + wVirtualKeyCode = (ConsoleKeyMapping.VK)73, + wVirtualScanCode = 23 + } + }); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Key, + KeyEvent = new() + { + bKeyDown = false, + UnicodeChar = 'i', + dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + wVirtualKeyCode = (ConsoleKeyMapping.VK)73, + wVirtualScanCode = 23 + } + }); var processor = new WindowsInputProcessor (queue); - List ups = new List (); - List downs = new List (); + List ups = new (); + List downs = new (); processor.KeyUp += (s, e) => { ups.Add (e); }; processor.KeyDown += (s, e) => { downs.Add (e); }; @@ -81,27 +88,27 @@ public void Test_ProcessQueue_CapitalHLowerE () Assert.Equal (Key.I, downs [1]); } - [Fact] public void Test_ProcessQueue_Mouse_Move () { - var queue = new ConcurrentQueue (); - - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Mouse, - MouseEvent = new WindowsConsole.MouseEventRecord - { - MousePosition = new WindowsConsole.Coord(32,31), - ButtonState = WindowsConsole.ButtonState.NoButtonPressed, - ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - EventFlags = WindowsConsole.EventFlags.MouseMoved - } - }); + ConcurrentQueue queue = new (); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Mouse, + MouseEvent = new() + { + MousePosition = new (32, 31), + ButtonState = ButtonState.NoButtonPressed, + ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + EventFlags = WindowsConsole.EventFlags.MouseMoved + } + }); var processor = new WindowsInputProcessor (queue); - List mouseEvents = new List (); + List mouseEvents = new (); processor.MouseEvent += (s, e) => { mouseEvents.Add (e); }; @@ -109,35 +116,36 @@ public void Test_ProcessQueue_Mouse_Move () processor.ProcessQueue (); - var s = Assert.Single (mouseEvents); - Assert.Equal (s.Flags,MouseFlags.ReportMousePosition); - Assert.Equal (s.ScreenPosition,new Point (32,31)); + MouseEventArgs s = Assert.Single (mouseEvents); + Assert.Equal (MouseFlags.ReportMousePosition, s.Flags); + Assert.Equal (s.ScreenPosition, new (32, 31)); } [Theory] - [InlineData(WindowsConsole.ButtonState.Button1Pressed,MouseFlags.Button1Pressed)] - [InlineData (WindowsConsole.ButtonState.Button2Pressed, MouseFlags.Button2Pressed)] - [InlineData (WindowsConsole.ButtonState.Button3Pressed, MouseFlags.Button3Pressed)] - [InlineData (WindowsConsole.ButtonState.Button4Pressed, MouseFlags.Button4Pressed)] - internal void Test_ProcessQueue_Mouse_Pressed (WindowsConsole.ButtonState state,MouseFlags expectedFlag ) + [InlineData (ButtonState.Button1Pressed, MouseFlags.Button1Pressed)] + [InlineData (ButtonState.Button2Pressed, MouseFlags.Button2Pressed)] + [InlineData (ButtonState.Button3Pressed, MouseFlags.Button3Pressed)] + [InlineData (ButtonState.Button4Pressed, MouseFlags.Button4Pressed)] + internal void Test_ProcessQueue_Mouse_Pressed (ButtonState state, MouseFlags expectedFlag) { - var queue = new ConcurrentQueue (); - - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Mouse, - MouseEvent = new WindowsConsole.MouseEventRecord - { - MousePosition = new WindowsConsole.Coord (32, 31), - ButtonState = state, - ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - EventFlags = WindowsConsole.EventFlags.MouseMoved - } - }); + ConcurrentQueue queue = new (); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Mouse, + MouseEvent = new() + { + MousePosition = new (32, 31), + ButtonState = state, + ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + EventFlags = WindowsConsole.EventFlags.MouseMoved + } + }); var processor = new WindowsInputProcessor (queue); - List mouseEvents = new List (); + List mouseEvents = new (); processor.MouseEvent += (s, e) => { mouseEvents.Add (e); }; @@ -145,34 +153,34 @@ internal void Test_ProcessQueue_Mouse_Pressed (WindowsConsole.ButtonState state, processor.ProcessQueue (); - var s = Assert.Single (mouseEvents); + MouseEventArgs s = Assert.Single (mouseEvents); Assert.Equal (s.Flags, MouseFlags.ReportMousePosition | expectedFlag); - Assert.Equal (s.ScreenPosition, new Point (32, 31)); + Assert.Equal (s.ScreenPosition, new (32, 31)); } - [Theory] [InlineData (100, MouseFlags.WheeledUp)] - [InlineData ( -100, MouseFlags.WheeledDown)] + [InlineData (-100, MouseFlags.WheeledDown)] internal void Test_ProcessQueue_Mouse_Wheel (int wheelValue, MouseFlags expectedFlag) { - var queue = new ConcurrentQueue (); - - queue.Enqueue (new InputRecord () - { - EventType = WindowsConsole.EventType.Mouse, - MouseEvent = new WindowsConsole.MouseEventRecord - { - MousePosition = new WindowsConsole.Coord (32, 31), - ButtonState = (WindowsConsole.ButtonState)wheelValue, - ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - EventFlags = WindowsConsole.EventFlags.MouseWheeled - } - }); + ConcurrentQueue queue = new (); + + queue.Enqueue ( + new() + { + EventType = WindowsConsole.EventType.Mouse, + MouseEvent = new() + { + MousePosition = new (32, 31), + ButtonState = (ButtonState)wheelValue, + ControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + EventFlags = WindowsConsole.EventFlags.MouseWheeled + } + }); var processor = new WindowsInputProcessor (queue); - List mouseEvents = new List (); + List mouseEvents = new (); processor.MouseEvent += (s, e) => { mouseEvents.Add (e); }; @@ -180,126 +188,133 @@ internal void Test_ProcessQueue_Mouse_Wheel (int wheelValue, MouseFlags expected processor.ProcessQueue (); - var s = Assert.Single (mouseEvents); - Assert.Equal (s.Flags,expectedFlag); - Assert.Equal (s.ScreenPosition, new Point (32, 31)); + MouseEventArgs s = Assert.Single (mouseEvents); + Assert.Equal (s.Flags, expectedFlag); + Assert.Equal (s.ScreenPosition, new (32, 31)); } public static IEnumerable MouseFlagTestData () { yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button1Pressed, MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.Button1Pressed, MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) } }; yield return new object [] { - new Tuple[] + new [] { - Tuple.Create ( ButtonState.Button2Pressed, MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button2Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.Button2Pressed, MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button2Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) } - }; + }; + yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) } }; yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button4Pressed, MouseFlags.Button4Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button4Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.Button4Pressed, MouseFlags.Button4Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button4Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) } }; yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition | MouseFlags.ReportMousePosition) } }; // Tests for holding down 2 buttons at once and releasing them one after the other yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button1Pressed | ButtonState.Button2Pressed, MouseFlags.Button1Pressed | MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.Button1Pressed, MouseFlags.Button1Pressed | MouseFlags.Button2Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) + Tuple.Create ( + ButtonState.Button1Pressed | ButtonState.Button2Pressed, + MouseFlags.Button1Pressed | MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.Button1Pressed, MouseFlags.Button1Pressed | MouseFlags.Button2Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) } }; yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button3Pressed | ButtonState.Button4Pressed, MouseFlags.Button3Pressed | MouseFlags.Button4Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.Button4Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) + Tuple.Create ( + ButtonState.Button3Pressed | ButtonState.Button4Pressed, + MouseFlags.Button3Pressed | MouseFlags.Button4Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.Button4Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) } }; // Test for holding down 2 buttons at once and releasing them simultaneously yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button1Pressed | ButtonState.Button2Pressed, MouseFlags.Button1Pressed | MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.Button2Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) + Tuple.Create ( + ButtonState.Button1Pressed | ButtonState.Button2Pressed, + MouseFlags.Button1Pressed | MouseFlags.Button2Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button1Released | MouseFlags.Button2Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) } }; // Test that rightmost and button 3 are the same button so 2 states is still only 1 flag yield return new object [] { - new Tuple[] + new [] { - Tuple.Create(ButtonState.Button3Pressed | ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.Button3Pressed | ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + // Can swap between without raising the released - Tuple.Create(ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.Button3Pressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.RightmostButtonPressed, MouseFlags.Button3Pressed | MouseFlags.ReportMousePosition), // Now with neither we get released - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), - Tuple.Create(ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.Button3Released | MouseFlags.ReportMousePosition), + Tuple.Create (ButtonState.NoButtonPressed, MouseFlags.ReportMousePosition) } }; } [Theory] [MemberData (nameof (MouseFlagTestData))] - internal void MouseFlags_Should_Map_Correctly (Tuple[] inputOutputPairs) + internal void MouseFlags_Should_Map_Correctly (Tuple [] inputOutputPairs) { var processor = new WindowsInputProcessor (new ()); - foreach (var pair in inputOutputPairs) + foreach (Tuple pair in inputOutputPairs) { var mockEvent = new MouseEventRecord { ButtonState = pair.Item1 }; - var result = processor.ToDriverMouse (mockEvent); + MouseEventArgs result = processor.ToDriverMouse (mockEvent); Assert.Equal (pair.Item2, result.Flags); } } } - diff --git a/Tests/UnitTests/Dialogs/DialogTests.cs b/Tests/UnitTests/Dialogs/DialogTests.cs index b058598165..47e843e187 100644 --- a/Tests/UnitTests/Dialogs/DialogTests.cs +++ b/Tests/UnitTests/Dialogs/DialogTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; using static Terminal.Gui.Application; @@ -48,7 +47,7 @@ public void Add_Button_Works () Width = width, Height = 1, ButtonAlignment = Alignment.Center, - Buttons = [new() { Text = btn1Text }] + Buttons = [new () { Text = btn1Text }] }; // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) @@ -76,7 +75,7 @@ public void Add_Button_Works () Width = width, Height = 1, ButtonAlignment = Alignment.Fill, - Buttons = [new() { Text = btn1Text }] + Buttons = [new () { Text = btn1Text }] }; // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) @@ -103,7 +102,7 @@ public void Add_Button_Works () Width = width, Height = 1, ButtonAlignment = Alignment.End, - Buttons = [new() { Text = btn1Text }] + Buttons = [new () { Text = btn1Text }] }; // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) @@ -131,7 +130,7 @@ public void Add_Button_Works () Width = width, Height = 1, ButtonAlignment = Alignment.Start, - Buttons = [new() { Text = btn1Text }] + Buttons = [new () { Text = btn1Text }] }; // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) @@ -180,14 +179,14 @@ public void ButtonAlignment_Four () // Default - Center (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -197,14 +196,14 @@ public void ButtonAlignment_Four () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -214,14 +213,14 @@ public void ButtonAlignment_Four () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -231,14 +230,14 @@ public void ButtonAlignment_Four () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -275,14 +274,14 @@ public void ButtonAlignment_Four_On_Too_Small_Width () $"{Glyphs.VLine} yes {Glyphs.RightBracket}{btn2}{btn3}{Glyphs.LeftBracket} never{Glyphs.VLine}"; (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); Assert.Equal (new (width, 1), dlg.Frame.Size); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); @@ -293,14 +292,14 @@ public void ButtonAlignment_Four_On_Too_Small_Width () $"{Glyphs.VLine}{Glyphs.LeftBracket} yes {Glyphs.LeftBracket} no {Glyphs.LeftBracket} maybe {Glyphs.LeftBracket} never {Glyphs.RightBracket}{Glyphs.VLine}"; (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -310,14 +309,14 @@ public void ButtonAlignment_Four_On_Too_Small_Width () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -326,14 +325,14 @@ public void ButtonAlignment_Four_On_Too_Small_Width () buttonRow = $"{Glyphs.VLine}{btn1}{btn2}{btn3}{Glyphs.LeftBracket} neve{Glyphs.VLine}"; (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -369,14 +368,14 @@ public void ButtonAlignment_Four_WideOdd () // Default - Center (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -386,14 +385,14 @@ public void ButtonAlignment_Four_WideOdd () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -403,14 +402,14 @@ public void ButtonAlignment_Four_WideOdd () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -420,14 +419,14 @@ public void ButtonAlignment_Four_WideOdd () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -465,14 +464,14 @@ public void ButtonAlignment_Four_Wider () // Default - Center (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -482,14 +481,14 @@ public void ButtonAlignment_Four_Wider () Assert.Equal (width, buttonRow.GetColumns ()); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -499,14 +498,14 @@ public void ButtonAlignment_Four_Wider () Assert.Equal (width, buttonRow.GetColumns ()); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -516,14 +515,14 @@ public void ButtonAlignment_Four_Wider () Assert.Equal (width, buttonRow.GetColumns ()); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text }, - new Button { Text = btn4Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text }, + new Button { Text = btn4Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -550,11 +549,11 @@ public void ButtonAlignment_One () d.SetBufferSize (width, 1); (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btnText } - ); + title, + width, + Alignment.Center, + new Button { Text = btnText } + ); // Center DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); @@ -567,11 +566,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btnText } - ); + title, + width, + Alignment.Fill, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -582,11 +581,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btnText } - ); + title, + width, + Alignment.End, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -597,11 +596,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btnText } - ); + title, + width, + Alignment.Start, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -614,11 +613,11 @@ public void ButtonAlignment_One () d.SetBufferSize (width, 1); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btnText } - ); + title, + width, + Alignment.Center, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -629,11 +628,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btnText } - ); + title, + width, + Alignment.Fill, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -644,11 +643,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btnText } - ); + title, + width, + Alignment.End, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -659,11 +658,11 @@ public void ButtonAlignment_One () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btnText } - ); + title, + width, + Alignment.Start, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -695,13 +694,13 @@ public void ButtonAlignment_Three () d.SetBufferSize (buttonRow.Length, 3); (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -711,13 +710,13 @@ public void ButtonAlignment_Three () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -727,13 +726,13 @@ public void ButtonAlignment_Three () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -743,13 +742,13 @@ public void ButtonAlignment_Three () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text }, - new Button { Text = btn3Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text }, + new Button { Text = btn3Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -779,12 +778,12 @@ public void ButtonAlignment_Two () d.SetBufferSize (buttonRow.Length, 3); (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btn1Text }, - new Button { Text = btn2Text } - ); + title, + width, + Alignment.Center, + new Button { Text = btn1Text }, + new Button { Text = btn2Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -794,12 +793,12 @@ public void ButtonAlignment_Two () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Fill, - new Button { Text = btn1Text }, - new Button { Text = btn2Text } - ); + title, + width, + Alignment.Fill, + new Button { Text = btn1Text }, + new Button { Text = btn2Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -809,12 +808,12 @@ public void ButtonAlignment_Two () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.End, - new Button { Text = btn1Text }, - new Button { Text = btn2Text } - ); + title, + width, + Alignment.End, + new Button { Text = btn1Text }, + new Button { Text = btn2Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -824,12 +823,12 @@ public void ButtonAlignment_Two () Assert.Equal (width, buttonRow.Length); (runstate, dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Start, - new Button { Text = btn1Text }, - new Button { Text = btn2Text } - ); + title, + width, + Alignment.Start, + new Button { Text = btn1Text }, + new Button { Text = btn2Text } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -863,8 +862,8 @@ public void ButtonAlignment_Two_Hidden () Button button1, button2; // Default (Center) - button1 = new() { Text = btn1Text }; - button2 = new() { Text = btn2Text }; + button1 = new () { Text = btn1Text }; + button2 = new () { Text = btn2Text }; (runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Center, button1, button2); button1.Visible = false; RunIteration (ref runstate, firstIteration); @@ -875,8 +874,8 @@ public void ButtonAlignment_Two_Hidden () // Justify Assert.Equal (width, buttonRow.Length); - button1 = new() { Text = btn1Text }; - button2 = new() { Text = btn2Text }; + button1 = new () { Text = btn1Text }; + button2 = new () { Text = btn2Text }; (runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Fill, button1, button2); button1.Visible = false; RunIteration (ref runstate, firstIteration); @@ -887,8 +886,8 @@ public void ButtonAlignment_Two_Hidden () // Right Assert.Equal (width, buttonRow.Length); - button1 = new() { Text = btn1Text }; - button2 = new() { Text = btn2Text }; + button1 = new () { Text = btn1Text }; + button2 = new () { Text = btn2Text }; (runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.End, button1, button2); button1.Visible = false; RunIteration (ref runstate, firstIteration); @@ -898,8 +897,8 @@ public void ButtonAlignment_Two_Hidden () // Left Assert.Equal (width, buttonRow.Length); - button1 = new() { Text = btn1Text }; - button2 = new() { Text = btn2Text }; + button1 = new () { Text = btn1Text }; + button2 = new () { Text = btn2Text }; (runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Start, button1, button2); button1.Visible = false; RunIteration (ref runstate, firstIteration); @@ -1079,30 +1078,30 @@ public void Dialog_Opened_From_Another_Dialog () string expected = null; btn1.Accepting += (s, e) => - { - btn2 = new () { Text = "Show Sub" }; - btn3 = new () { Text = "Close" }; - btn3.Accepting += (s, e) => RequestStop (); - - btn2.Accepting += (s, e) => - { - // Don't test MessageBox in Dialog unit tests! - var subBtn = new Button { Text = "Ok", IsDefault = true }; - var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] }; - subBtn.Accepting += (s, e) => RequestStop (subDlg); - Run (subDlg); - }; - - var dlg = new Dialog - { - Buttons = [btn2, btn3], - Width = Dim.Percent (85), - Height = Dim.Percent (85) - }; - - Run (dlg); - dlg.Dispose (); - }; + { + btn2 = new () { Text = "Show Sub" }; + btn3 = new () { Text = "Close" }; + btn3.Accepting += (s, e) => RequestStop (); + + btn2.Accepting += (s, e) => + { + // Don't test MessageBox in Dialog unit tests! + var subBtn = new Button { Text = "Ok", IsDefault = true }; + var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] }; + subBtn.Accepting += (s, e) => RequestStop (subDlg); + Run (subDlg); + }; + + var dlg = new Dialog + { + Buttons = [btn2, btn3], + Width = Dim.Percent (85), + Height = Dim.Percent (85) + }; + + Run (dlg); + dlg.Dispose (); + }; var btn = $"{Glyphs.LeftBracket}{Glyphs.LeftDefaultIndicator} Ok {Glyphs.RightDefaultIndicator}{Glyphs.RightBracket}"; @@ -1116,8 +1115,8 @@ public void Dialog_Opened_From_Another_Dialog () switch (iterations) { case 0: - Top.SetNeedsLayout(); - Top.SetNeedsDraw(); + Top.SetNeedsLayout (); + Top.SetNeedsDraw (); LayoutAndDraw (); break; @@ -1147,7 +1146,7 @@ public void Dialog_Opened_From_Another_Dialog () LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @$" + @$" ┌───────────────────────┐ │ ┌──────────────────┐ │ │ │ya │ │ @@ -1156,8 +1155,8 @@ public void Dialog_Opened_From_Another_Dialog () │ └──────────────────┘ │ │{Glyphs.LeftBracket} Show Sub {Glyphs.RightBracket} {Glyphs.LeftBracket} Close {Glyphs.RightBracket} │ └───────────────────────┘", - _output - ); + _output + ); Assert.False (Top.NewKeyDownEvent (Key.Enter)); @@ -1250,14 +1249,14 @@ public void Location_When_Application_Top_Not_Default () Assert.Equal (new (expected, expected), d.Frame.Location); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌───┐ │ │ │ │ │ │ └───┘", - _output - ); + _output + ); d.Dispose (); } @@ -1281,11 +1280,11 @@ public void One_Button_Works () d.SetBufferSize (buttonRow.Length, 10); (runstate, Dialog dlg) = BeginButtonTestDialog ( - title, - width, - Alignment.Center, - new Button { Text = btnText } - ); + title, + width, + Alignment.Center, + new Button { Text = btnText } + ); DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); dlg.Dispose (); @@ -1376,7 +1375,7 @@ params Button [] btns RunState runState = Begin (dlg); - dlg.SetNeedsDraw(); + dlg.SetNeedsDraw (); dlg.SetNeedsLayout (); dlg.Layout (); dlg.Draw (); diff --git a/Tests/UnitTests/Dialogs/MessageBoxTests.cs b/Tests/UnitTests/Dialogs/MessageBoxTests.cs index c873686f75..3b93d98191 100644 --- a/Tests/UnitTests/Dialogs/MessageBoxTests.cs +++ b/Tests/UnitTests/Dialogs/MessageBoxTests.cs @@ -1,6 +1,5 @@ using System.Text; -using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; -using UnitTests; +using UICatalog; using UnitTests; using Xunit.Abstractions; @@ -19,7 +18,7 @@ public void KeyBindings_Enter_Causes_Focused_Button_Click_No_Accept () var iteration = 0; - int btnAcceptCount = 0; + var btnAcceptCount = 0; Application.Iteration += (s, a) => { @@ -37,7 +36,7 @@ public void KeyBindings_Enter_Causes_Focused_Button_Click_No_Accept () // Tab to btn2 Application.RaiseKeyDownEvent (Key.Tab); - Button btn = Application.Navigation!.GetFocused () as Button; + var btn = Application.Navigation!.GetFocused () as Button; btn.Accepting += (sender, e) => { btnAcceptCount++; }; @@ -102,7 +101,7 @@ public void KeyBindings_Space_Causes_Focused_Button_Click_No_Accept () var iteration = 0; - int btnAcceptCount = 0; + var btnAcceptCount = 0; Application.Iteration += (s, a) => { @@ -120,7 +119,7 @@ public void KeyBindings_Space_Causes_Focused_Button_Click_No_Accept () // Tab to btn2 Application.RaiseKeyDownEvent (Key.Tab); - Button btn = Application.Navigation!.GetFocused () as Button; + var btn = Application.Navigation!.GetFocused () as Button; btn.Accepting += (sender, e) => { btnAcceptCount++; }; @@ -138,7 +137,6 @@ public void KeyBindings_Space_Causes_Focused_Button_Click_No_Accept () Assert.Equal (1, result); Assert.Equal (1, btnAcceptCount); - } [Theory] @@ -161,7 +159,7 @@ public void Location_And_Size_Correct (string message, bool wrapMessage, bool ha Dialog.DefaultShadow = ShadowStyle.None; Button.DefaultShadow = ShadowStyle.None; - Rectangle mbFrame = Rectangle.Empty; + var mbFrame = Rectangle.Empty; Application.Iteration += (s, a) => { @@ -224,30 +222,30 @@ public void Message_With_Spaces_WrapMessage_False () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ╔════════════════╗ ║ ff ff ff ff ff ║ ║ ⟦► btn ◄⟧║ ╚════════════════╝", - _output - ); + _output + ); Application.RequestStop (); // Really long text - MessageBox.Query (string.Empty, new string ('f', 500), 0, false, "btn"); + MessageBox.Query (string.Empty, new ('f', 500), 0, false, "btn"); } else if (iterations == 2) { Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ╔════════════════╗ ║ffffffffffffffff║ ║ ⟦► btn ◄⟧║ ╚════════════════╝", - _output - ); + _output + ); Application.RequestStop (); } }; @@ -296,7 +294,7 @@ public void Message_With_Spaces_WrapMessage_True () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ╔══════════════╗ ║ff ff ff ff ff║ ║ff ff ff ff ff║ @@ -304,19 +302,19 @@ public void Message_With_Spaces_WrapMessage_True () ║ ff ff ║ ║ ⟦► btn ◄⟧║ ╚══════════════╝", - _output - ); + _output + ); Application.RequestStop (); // Really long text - MessageBox.Query (string.Empty, new string ('f', 500), 0, true, "btn"); + MessageBox.Query (string.Empty, new ('f', 500), 0, true, "btn"); } else if (iterations == 2) { Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @$" + @" ╔════════════════╗ ║ffffffffffffffff║ ║ffffffffffffffff║ @@ -326,8 +324,8 @@ public void Message_With_Spaces_WrapMessage_True () ║ffffffffffffffff║ ║fffffff⟦► btn ◄⟧║ ╚════════════════╝", - _output - ); + _output + ); Application.RequestStop (); } }; @@ -463,8 +461,8 @@ public void UICatalog_AboutBox () if (iterations == 0) { MessageBox.Query ( - title: "", - message: UICatalog.UICatalogApp.GetAboutBoxMessage (), + "", + UICatalogApp.GetAboutBoxMessage (), wrapMessage: false, buttons: "_Ok" ); @@ -475,23 +473,23 @@ public void UICatalog_AboutBox () { Application.LayoutAndDraw (); - string expectedText = """ - ┌────────────────────────────────────────────────────────────────────┐ - │ ╔═══════════════════════════════════════════════════════════╗ │ - │ ║UI Catalog: A comprehensive sample library and test app for║ │ - │ ║ ║ │ - │ ║ _______ _ _ _____ _ ║ │ - │ ║|__ __| (_) | | / ____| (_) ║ │ - │ ║ | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ ║ │ - │ ║ | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | ║ │ - │ ║ | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | ║ │ - │ ║ |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| ║ │ - │ ║ ║ │ - │ ║ v2 - Pre-Alpha ║ │ - │ ║ ⟦► Ok ◄⟧║ │ - │ ╚═══════════════════════════════════════════════════════════╝ │ - └────────────────────────────────────────────────────────────────────┘ - """; + var expectedText = """ + ┌────────────────────────────────────────────────────────────────────┐ + │ ╔═══════════════════════════════════════════════════════════╗ │ + │ ║UI Catalog: A comprehensive sample library and test app for║ │ + │ ║ ║ │ + │ ║ _______ _ _ _____ _ ║ │ + │ ║|__ __| (_) | | / ____| (_) ║ │ + │ ║ | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ ║ │ + │ ║ | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | ║ │ + │ ║ | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | ║ │ + │ ║ |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| ║ │ + │ ║ ║ │ + │ ║ v2 - Pre-Alpha ║ │ + │ ║ ⟦► Ok ◄⟧║ │ + │ ╚═══════════════════════════════════════════════════════════╝ │ + └────────────────────────────────────────────────────────────────────┘ + """; DriverAssert.AssertDriverContentsAre (expectedText, _output); @@ -506,11 +504,10 @@ public void UICatalog_AboutBox () } [Theory] - [SetupFakeDriver] [MemberData (nameof (AcceptingKeys))] public void Button_IsDefault_True_Return_His_Index_On_Accepting (Key key) { - Application.Init (); + Application.Init (new FakeDriver ()); Application.Iteration += (_, _) => Assert.True (Application.RaiseKeyDownEvent (key)); int res = MessageBox.Query ("hey", "IsDefault", "Yes", "No"); diff --git a/Tests/UnitTests/Dialogs/WizardTests.cs b/Tests/UnitTests/Dialogs/WizardTests.cs index a73d0e15f1..71504333b9 100644 --- a/Tests/UnitTests/Dialogs/WizardTests.cs +++ b/Tests/UnitTests/Dialogs/WizardTests.cs @@ -462,7 +462,7 @@ public void OneStepWizard_Shows () var wizard = new Wizard { Title = title, Width = width, Height = height }; wizard.AddStep (new() { Title = stepTitle }); - //wizard.LayoutSubviews (); + //wizard.LayoutSubViews (); var firstIteration = false; RunState runstate = Application.Begin (wizard); Application.RunIteration (ref runstate, firstIteration); diff --git a/Tests/UnitTests/Drawing/LineCanvasTests.cs b/Tests/UnitTests/Drawing/LineCanvasTests.cs index 7ef1a449cd..132f84ac73 100644 --- a/Tests/UnitTests/Drawing/LineCanvasTests.cs +++ b/Tests/UnitTests/Drawing/LineCanvasTests.cs @@ -1,11 +1,10 @@ using System.Text; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.DrawingTests; -public class LineCanvasTests (ITestOutputHelper _output) +public class LineCanvasTests (ITestOutputHelper output) { [Theory] @@ -296,7 +295,7 @@ string expected lc.AddLine (new (x1, y1), len1, o1, s1); lc.AddLine (new (x2, y2), len2, o2, s2); - OutputAssert.AssertEqual (_output, expected, lc.ToString ()); + OutputAssert.AssertEqual (output, expected, lc.ToString ()); v.Dispose (); } @@ -505,12 +504,12 @@ public void Viewport_Specific () Assert.Equal (new (x, y, 4, 2), lc.Bounds); OutputAssert.AssertEqual ( - _output, - @" + output, + @" ╔╡╞╗ ║ ║", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); } [Fact] @@ -555,12 +554,12 @@ public void Viewport_Specific_With_Ustring () Assert.Equal (new (x, y, 4, 2), lc.Bounds); OutputAssert.AssertEqual ( - _output, - @" + output, + @" ╔╡╞╗ ║ ║", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); } [Fact] @@ -598,7 +597,7 @@ public void Length_0_Is_1_Long (int x, int y, Orientation orientation, string ex // Add a line at 5, 5 that's has length of 1 canvas.AddLine (new (x, y), 1, orientation, LineStyle.Single); - OutputAssert.AssertEqual (_output, $"{expected}", $"{canvas}"); + OutputAssert.AssertEqual (output, $"{expected}", $"{canvas}"); } // X is offset by 2 @@ -655,7 +654,7 @@ public void Length_n_Is_n_Long (int x, int y, int length, Orientation orientatio canvas.AddLine (new (x, y), length, orientation, LineStyle.Single); var result = canvas.ToString (); - OutputAssert.AssertEqual (_output, expected, result); + OutputAssert.AssertEqual (output, expected, result); } [Fact] @@ -682,7 +681,7 @@ public void Length_Zero_Alone_Is_Line (Orientation orientation, string expected) // Add a line at 0, 0 that's has length of 0 lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); - OutputAssert.AssertEqual (_output, expected, $"{lc}"); + OutputAssert.AssertEqual (output, expected, $"{lc}"); } [InlineData (Orientation.Horizontal, "┼")] @@ -703,7 +702,7 @@ public void Length_Zero_Cross_Is_Cross (Orientation orientation, string expected // Add a line at 0, 0 that's has length of 0 lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); - OutputAssert.AssertEqual (_output, expected, $"{lc}"); + OutputAssert.AssertEqual (output, expected, $"{lc}"); } [InlineData (Orientation.Horizontal, "╥")] @@ -726,7 +725,7 @@ public void Length_Zero_NextTo_Opposite_Is_T (Orientation orientation, string ex // Add a line at 0, 0 that's has length of 0 lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); - OutputAssert.AssertEqual (_output, expected, $"{lc}"); + OutputAssert.AssertEqual (output, expected, $"{lc}"); } [Fact] @@ -742,7 +741,7 @@ public void TestLineCanvas_LeaveMargin_Top1_Left1 () @" ┌─ │ "; - OutputAssert.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}"); + OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}"); } [Fact] @@ -769,7 +768,7 @@ public void TestLineCanvas_Window_Heavy () ┣━━━━╋━━━┫ ┃ ┃ ┃ ┗━━━━┻━━━┛"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -800,7 +799,7 @@ public void TestLineCanvas_Window_HeavyTop_ThinSides (LineStyle thinStyle) │ │ │ ┕━━━━┷━━━┙ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -832,7 +831,7 @@ public void TestLineCanvas_Window_ThinTop_HeavySides (LineStyle thinStyle) ┖────┸───┚ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -850,7 +849,7 @@ public void Top_Left_From_TopRight_LeftUp () @" ┌─ │ "; - OutputAssert.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}"); + OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}"); } [Fact] @@ -880,12 +879,12 @@ public void Top_With_1Down () Assert.Equal (2, map.Count); OutputAssert.AssertEqual ( - _output, - @" + output, + @" ─ ─", - $"{Environment.NewLine}{canvas}" - ); + $"{Environment.NewLine}{canvas}" + ); } [Fact] @@ -893,7 +892,7 @@ public void Top_With_1Down () public void ToString_Empty () { var lc = new LineCanvas (); - OutputAssert.AssertEqual (_output, string.Empty, lc.ToString ()); + OutputAssert.AssertEqual (output, string.Empty, lc.ToString ()); } // 012 @@ -912,7 +911,7 @@ public void ToString_Positive_Horizontal_1Line_Offset (int x, int y, string expe { var lc = new LineCanvas (); lc.AddLine (new (x, y), 3, Orientation.Horizontal, LineStyle.Double); - OutputAssert.AssertEqual (_output, expected, $"{lc}"); + OutputAssert.AssertEqual (output, expected, $"{lc}"); } [InlineData (0, 0, 0, 0, "═══")] @@ -937,7 +936,7 @@ public void ToString_Positive_Horizontal_2Line_Offset (int x1, int y1, int x2, i lc.AddLine (new (x1, y1), 3, Orientation.Horizontal, LineStyle.Double); lc.AddLine (new (x2, y2), 3, Orientation.Horizontal, LineStyle.Double); - OutputAssert.AssertEqual (_output, expected, $"{lc}"); + OutputAssert.AssertEqual (output, expected, $"{lc}"); } // [Fact, SetupFakeDriver] @@ -997,7 +996,7 @@ string expected v.Draw (); - DriverAssert.AssertDriverContentsAre (expected, _output); + DriverAssert.AssertDriverContentsAre (expected, output); v.Dispose (); } @@ -1016,7 +1015,7 @@ public void View_Draws_Corner_Correct () @" ┌─ │"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1039,7 +1038,7 @@ public void View_Draws_Corner_NoOverlap () ── │ │"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1057,7 +1056,7 @@ public void View_Draws_Horizontal (LineStyle style) var looksLike = @" ──"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1073,7 +1072,7 @@ public void View_Draws_Horizontal_Double () var looksLike = @" ══"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1092,7 +1091,7 @@ public void View_Draws_Vertical (LineStyle style) @" │ │"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1109,7 +1108,7 @@ public void View_Draws_Vertical_Double () @" ║ ║"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1137,7 +1136,7 @@ public void View_Draws_Window_Double () ╠════╬═══╣ ║ ║ ║ ╚════╩═══╝"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1168,7 +1167,7 @@ public void View_Draws_Window_DoubleTop_SingleSides (LineStyle thinStyle) │ │ │ ╘════╧═══╛ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1205,7 +1204,7 @@ public void View_Draws_Window_Rounded () ├────┼───┤ │ │ │ ╰────┴───╯"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1237,7 +1236,7 @@ public void View_Draws_Window_SingleTop_DoubleSides (LineStyle thinStyle) ╙────╨───╜ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); v.Dispose (); } @@ -1264,7 +1263,7 @@ public void Window () ├────┼───┤ │ │ │ └────┴───┘"; - OutputAssert.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}"); + OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}"); } [Fact] @@ -1302,7 +1301,7 @@ public void Zero_Length_Intersections () var looksLike = @" ╔╡╞══╗ ║ ║"; - OutputAssert.AssertEqual (_output, looksLike, $"{Environment.NewLine}{lc}"); + OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{lc}"); } [Fact] @@ -1407,20 +1406,20 @@ private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0) LineCanvas canvasCopy = canvas = new (); v.DrawComplete += (s, e) => - { - v.FillRect (v.Viewport); - - foreach (KeyValuePair p in canvasCopy.GetMap ()) - { - v.AddRune ( - offsetX + p.Key.X, - offsetY + p.Key.Y, - p.Value - ); - } - - canvasCopy.Clear (); - }; + { + v.FillRect (v.Viewport); + + foreach (KeyValuePair p in canvasCopy.GetMap ()) + { + v.AddRune ( + offsetX + p.Key.X, + offsetY + p.Key.Y, + p.Value + ); + } + + canvasCopy.Clear (); + }; return v; } diff --git a/Tests/UnitTests/Drawing/RulerTests.cs b/Tests/UnitTests/Drawing/RulerTests.cs index f259a601e7..b30dfce8e7 100644 --- a/Tests/UnitTests/Drawing/RulerTests.cs +++ b/Tests/UnitTests/Drawing/RulerTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.DrawingTests; @@ -51,33 +50,33 @@ public void Draw_Horizontal () r.Draw (Point.Empty); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" |123456789|1234", - _output - ); + _output + ); // Postive offset r.Draw (new (1, 1)); DriverAssert.AssertDriverContentsAre ( - @" + @" |123456789|1234 |123456789|1234 ", - _output - ); + _output + ); // Negative offset r.Draw (new (-1, 3)); DriverAssert.AssertDriverContentsAre ( - @" + @" |123456789|1234 |123456789|1234 123456789|1234 ", - _output - ); + _output + ); } [Fact] @@ -92,7 +91,7 @@ public void Draw_Vertical () r.Draw (Point.Empty); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" - 1 2 @@ -108,13 +107,13 @@ public void Draw_Vertical () 2 3 4", - _output - ); + _output + ); r.Draw (new (1, 1)); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" - 1- 21 @@ -131,14 +130,14 @@ public void Draw_Vertical () 32 43 4", - _output - ); + _output + ); // Negative offset r.Draw (new (2, -1)); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" - 1 1-2 213 @@ -155,9 +154,8 @@ public void Draw_Vertical () 324 43 4 ", - _output - ); - + _output + ); } [Fact] diff --git a/Tests/UnitTests/Drawing/StraightLineExtensionsTests.cs b/Tests/UnitTests/Drawing/StraightLineExtensionsTests.cs index 5de27b9645..67dc6d68cb 100644 --- a/Tests/UnitTests/Drawing/StraightLineExtensionsTests.cs +++ b/Tests/UnitTests/Drawing/StraightLineExtensionsTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.DrawingTests; @@ -12,136 +11,136 @@ public void LineCanvasIntegrationTest () { var lc = new LineCanvas (); lc.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single); - lc.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single); - lc.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single); - lc.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single); + lc.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single); + lc.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Single); + lc.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌────────┐ │ │ │ │ │ │ └────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); IReadOnlyCollection origLines = lc.Lines; - lc = new LineCanvas (origLines.Exclude (Point.Empty, 10, Orientation.Horizontal)); + lc = new (origLines.Exclude (Point.Empty, 10, Orientation.Horizontal)); OutputAssert.AssertEqual ( - output, - @" + output, + @" │ │ │ │ │ │ └────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (0, 1), 10, Orientation.Horizontal)); + lc = new (origLines.Exclude (new (0, 1), 10, Orientation.Horizontal)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌────────┐ │ │ │ │ └────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (0, 2), 10, Orientation.Horizontal)); + lc = new (origLines.Exclude (new (0, 2), 10, Orientation.Horizontal)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌────────┐ │ │ │ │ └────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (0, 3), 10, Orientation.Horizontal)); + lc = new (origLines.Exclude (new (0, 3), 10, Orientation.Horizontal)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌────────┐ │ │ │ │ └────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (0, 4), 10, Orientation.Horizontal)); + lc = new (origLines.Exclude (new (0, 4), 10, Orientation.Horizontal)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌────────┐ │ │ │ │ │ │", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (Point.Empty, 10, Orientation.Vertical)); + lc = new (origLines.Exclude (Point.Empty, 10, Orientation.Vertical)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ────────┐ │ │ │ ────────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (1, 0), 10, Orientation.Vertical)); + lc = new (origLines.Exclude (new (1, 0), 10, Orientation.Vertical)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌ ───────┐ │ │ │ │ │ │ └ ───────┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (8, 0), 10, Orientation.Vertical)); + lc = new (origLines.Exclude (new (8, 0), 10, Orientation.Vertical)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌─────── ┐ │ │ │ │ │ │ └─────── ┘", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); - lc = new LineCanvas (origLines.Exclude (new Point (9, 0), 10, Orientation.Vertical)); + lc = new (origLines.Exclude (new (9, 0), 10, Orientation.Vertical)); OutputAssert.AssertEqual ( - output, - @" + output, + @" ┌──────── │ │ │ └────────", - $"{Environment.NewLine}{lc}" - ); + $"{Environment.NewLine}{lc}" + ); } #region Parallel Tests @@ -151,12 +150,12 @@ public void LineCanvasIntegrationTest () public void TestExcludeParallel_HorizontalLines_LeftOnly () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=3 to x=103 - .Exclude (new Point (3, 2), 100, Orientation.Horizontal) + .Exclude (new (3, 2), 100, Orientation.Horizontal) .ToArray (); // x=1 to x=2 @@ -170,12 +169,12 @@ public void TestExcludeParallel_HorizontalLines_LeftOnly () public void TestExcludeParallel_HorizontalLines_RightOnly () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=0 to x=2 - .Exclude (new Point (0, 2), 3, Orientation.Horizontal) + .Exclude (new (0, 2), 3, Orientation.Horizontal) .ToArray (); // x=3 to x=10 @@ -190,12 +189,12 @@ public void TestExcludeParallel_HorizontalLines_RightOnly () public void TestExcludeParallel_HorizontalLines_HorizontalSplit () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=4 to x=5 - .Exclude (new Point (4, 2), 2, Orientation.Horizontal) + .Exclude (new (4, 2), 2, Orientation.Horizontal) .ToArray (); // x=1 to x=3, @@ -218,12 +217,12 @@ public void TestExcludeParallel_HorizontalLines_HorizontalSplit () public void TestExcludeParallel_HorizontalLines_CoverCompletely () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=4 to x=5 - .Exclude (new Point (1, 2), 10, Orientation.Horizontal) + .Exclude (new (1, 2), 10, Orientation.Horizontal) .ToArray (); Assert.Empty (after); } @@ -233,12 +232,12 @@ public void TestExcludeParallel_HorizontalLines_CoverCompletely () public void TestExcludeParallel_VerticalLines_TopOnly () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=3 to y=103 - .Exclude (new Point (2, 3), 100, Orientation.Vertical) + .Exclude (new (2, 3), 100, Orientation.Vertical) .ToArray (); // y=1 to y=2 @@ -252,12 +251,12 @@ public void TestExcludeParallel_VerticalLines_TopOnly () public void TestExcludeParallel_HorizontalLines_BottomOnly () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=0 to y=2 - .Exclude (new Point (2, 0), 3, Orientation.Vertical) + .Exclude (new (2, 0), 3, Orientation.Vertical) .ToArray (); // y=3 to y=10 @@ -272,12 +271,12 @@ public void TestExcludeParallel_HorizontalLines_BottomOnly () public void TestExcludeParallel_VerticalLines_VerticalSplit () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=4 to y=5 - .Exclude (new Point (2, 4), 2, Orientation.Vertical) + .Exclude (new (2, 4), 2, Orientation.Vertical) .ToArray (); // y=1 to y=3, @@ -300,12 +299,12 @@ public void TestExcludeParallel_VerticalLines_VerticalSplit () public void TestExcludeParallel_VerticalLines_CoverCompletely () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=4 to y=5 - .Exclude (new Point (2, 1), 10, Orientation.Vertical) + .Exclude (new (2, 1), 10, Orientation.Vertical) .ToArray (); Assert.Empty (after); } @@ -319,12 +318,12 @@ public void TestExcludeParallel_VerticalLines_CoverCompletely () public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_Splits () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=3 y=0-10 - .Exclude (new Point (3, 0), 10, Orientation.Vertical) + .Exclude (new (3, 0), 10, Orientation.Vertical) .ToArray (); // x=1 to x=2, @@ -347,12 +346,12 @@ public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_Splits () public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipLeft () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=1 y=0-10 - .Exclude (new Point (1, 0), 10, Orientation.Vertical) + .Exclude (new (1, 0), 10, Orientation.Vertical) .ToArray (); // x=2 to x=10, @@ -368,12 +367,12 @@ public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipLeft ( public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipRight () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=10 y=0-10 - .Exclude (new Point (10, 0), 10, Orientation.Vertical) + .Exclude (new (10, 0), 10, Orientation.Vertical) .ToArray (); // x=1 to x=9, @@ -389,7 +388,7 @@ public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipRight public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissLeft () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } @@ -406,12 +405,12 @@ public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissLeft ( public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissRight () { // x=1 to x=10 - var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single); + var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude x=11 y=0-10 - .Exclude (new Point (11, 0), 10, Orientation.Vertical) + .Exclude (new (11, 0), 10, Orientation.Vertical) .ToArray (); // Exclusion line is too far to the right so hits nothing @@ -423,12 +422,12 @@ public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissRight public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipTop () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=1 x=0-10 - .Exclude (new Point (0, 1), 10, Orientation.Horizontal) + .Exclude (new (0, 1), 10, Orientation.Horizontal) .ToArray (); // y=2 to y=10, @@ -444,12 +443,12 @@ public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipTop () public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipBottom () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=10 x=0-10 - .Exclude (new Point (0, 10), 10, Orientation.Horizontal) + .Exclude (new (0, 10), 10, Orientation.Horizontal) .ToArray (); // y=1 to y=9, @@ -465,7 +464,7 @@ public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipBottom public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissTop () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } @@ -482,12 +481,12 @@ public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissTop () public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissBottom () { // y=1 to y=10 - var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single); + var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single); StraightLine [] after = new [] { l1 } // exclude y=11 x=0-10 - .Exclude (new Point (0, 11), 10, Orientation.Horizontal) + .Exclude (new (0, 11), 10, Orientation.Horizontal) .ToArray (); // Exclusion line is too far to the right so hits nothing diff --git a/Tests/UnitTests/Drawing/ThicknessTests.cs b/Tests/UnitTests/Drawing/ThicknessTests.cs index fb75aacffa..40aae866ce 100644 --- a/Tests/UnitTests/Drawing/ThicknessTests.cs +++ b/Tests/UnitTests/Drawing/ThicknessTests.cs @@ -1,9 +1,9 @@ using System.Text; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.DrawingTests; + public class ThicknessTests (ITestOutputHelper output) { [Fact] @@ -15,28 +15,28 @@ public void DrawTests () var r = new Rectangle (5, 5, 40, 15); Application.Driver?.FillRect ( - new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), - (Rune)' ' - ); + new (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), + (Rune)' ' + ); t.Draw (r, ViewDiagnosticFlags.Thickness, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Test (Left=0,Top=0,Right=0,Bottom=0)", - output - ); + output + ); - t = new Thickness (1, 1, 1, 1); - r = new Rectangle (5, 5, 40, 15); + t = new (1, 1, 1, 1); + r = new (5, 5, 40, 15); Application.Driver?.FillRect ( - new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), - (Rune)' ' - ); + new (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), + (Rune)' ' + ); t.Draw (r, ViewDiagnosticFlags.Thickness, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT T T T T @@ -52,20 +52,20 @@ T T T T T T TTTest (Left=1,Top=1,Right=1,Bottom=1)TT", - output - ); + output + ); - t = new Thickness (1, 2, 3, 4); - r = new Rectangle (5, 5, 40, 15); + t = new (1, 2, 3, 4); + r = new (5, 5, 40, 15); Application.Driver?.FillRect ( - new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), - (Rune)' ' - ); + new (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), + (Rune)' ' + ); t.Draw (r, ViewDiagnosticFlags.Thickness, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT T TTT @@ -81,20 +81,20 @@ T TTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTest (Left=1,Top=2,Right=3,Bottom=4)TT", - output - ); + output + ); - t = new Thickness (-1, 1, 1, 1); - r = new Rectangle (5, 5, 40, 15); + t = new (-1, 1, 1, 1); + r = new (5, 5, 40, 15); Application.Driver?.FillRect ( - new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), - (Rune)' ' - ); + new (0, 0, Application.Driver!.Cols, Application.Driver!.Rows), + (Rune)' ' + ); t.Draw (r, ViewDiagnosticFlags.Thickness, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT T T @@ -110,8 +110,8 @@ T TTT T T TTest (Left=-1,Top=1,Right=1,Bottom=1)TT", - output - ); + output + ); } [Fact] @@ -133,7 +133,7 @@ public void DrawTests_Ruler () t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); DriverAssert.AssertDriverContentsAre ( - @" + @" ┌───────────────────────────────────────────┐ │ │ │ │ @@ -154,17 +154,17 @@ public void DrawTests_Ruler () │ │ │ │ └───────────────────────────────────────────┘", - output - ); + output + ); - t = new Thickness (1, 1, 1, 1); - r = new Rectangle (1, 1, 40, 15); + t = new (1, 1, 1, 1); + r = new (1, 1, 40, 15); top.SetNeedsDraw (); Application.RunIteration (ref rs); - t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); + t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); DriverAssert.AssertDriverContentsAre ( - @" + @" ┌───────────────────────────────────────────┐ │|123456789|123456789|123456789|123456789 │ │1 1 │ @@ -185,17 +185,17 @@ public void DrawTests_Ruler () │ │ │ │ └───────────────────────────────────────────┘", - output - ); + output + ); - t = new Thickness (1, 2, 3, 4); - r = new Rectangle (2, 2, 40, 15); + t = new (1, 2, 3, 4); + r = new (2, 2, 40, 15); top.SetNeedsDraw (); Application.RunIteration (ref rs); - t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); + t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌───────────────────────────────────────────┐ │ │ │ |123456789|123456789|123456789|123456789 │ @@ -216,17 +216,17 @@ public void DrawTests_Ruler () │ │ │ │ └───────────────────────────────────────────┘", - output - ); + output + ); - t = new Thickness (-1, 1, 1, 1); - r = new Rectangle (5, 5, 40, 15); + t = new (-1, 1, 1, 1); + r = new (5, 5, 40, 15); top.SetNeedsDraw (); Application.RunIteration (ref rs); t.Draw (r, ViewDiagnosticFlags.Ruler, "Test"); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌───────────────────────────────────────────┐ │ │ │ │ @@ -247,9 +247,8 @@ public void DrawTests_Ruler () │ 2 │ 3 └────|123456789|123456789|123456789|123456789", - output - ); + output + ); top.Dispose (); } - } diff --git a/Tests/UnitTests/FileServices/FileDialogTests.cs b/Tests/UnitTests/FileServices/FileDialogTests.cs index 269670509b..bb074a8a17 100644 --- a/Tests/UnitTests/FileServices/FileDialogTests.cs +++ b/Tests/UnitTests/FileServices/FileDialogTests.cs @@ -33,7 +33,7 @@ public void CancelSelection (bool cancel) public void DirectTyping_Allowed () { FileDialog dlg = GetInitializedFileDialog (); - TextField tf = dlg.Subviews.OfType ().First (t => t.HasFocus); + TextField tf = dlg.SubViews.OfType ().First (t => t.HasFocus); tf.ClearAllSelection (); tf.CursorPosition = tf.Text.Length; Assert.True (tf.HasFocus); @@ -321,7 +321,7 @@ public void OnLoad_TextBoxIsFocused () { FileDialog dlg = GetInitializedFileDialog (); - View tf = dlg.Subviews.FirstOrDefault (t => t.HasFocus); + View tf = dlg.SubViews.FirstOrDefault (t => t.HasFocus); Assert.NotNull (tf); Assert.IsType (tf); dlg.Dispose (); @@ -793,9 +793,9 @@ private TextField GetTextField (FileDialog dlg, FileDialogPart part) switch (part) { case FileDialogPart.Path: - return dlg.Subviews.OfType ().ElementAt (0); + return dlg.SubViews.OfType ().ElementAt (0); case FileDialogPart.SearchField: - return dlg.Subviews.OfType ().ElementAt (1); + return dlg.SubViews.OfType ().ElementAt (1); default: throw new ArgumentOutOfRangeException (nameof (part), part, null); } @@ -803,8 +803,8 @@ private TextField GetTextField (FileDialog dlg, FileDialogPart part) private TableView GetTableView (FileDialog dlg) { - var tile = dlg.Subviews.OfType ().Single (); - return (TableView)tile.Tiles.ElementAt (1).ContentView.Subviews.ElementAt(0); + var tile = dlg.SubViews.OfType ().Single (); + return (TableView)tile.Tiles.ElementAt (1).ContentView.SubViews.ElementAt(0); } private enum FileDialogPart diff --git a/Tests/UnitTests/TestsAllViews.cs b/Tests/UnitTests/TestsAllViews.cs index a3ab97b45d..76daf0f8ef 100644 --- a/Tests/UnitTests/TestsAllViews.cs +++ b/Tests/UnitTests/TestsAllViews.cs @@ -1,5 +1,6 @@ #nullable enable - +using System.Drawing; +using System.Reflection; using Terminal.Gui; namespace UnitTests; @@ -9,13 +10,23 @@ namespace UnitTests; /// public class TestsAllViews { + /// + /// Gets all view types. + /// public static IEnumerable AllViewTypes => typeof (View).Assembly .GetTypes () - .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && (type.IsSubclassOf (typeof (View)) || type == typeof (View))) + .Where ( + type => type is { IsClass: true, IsAbstract: false, IsPublic: true } + && (type.IsSubclassOf (typeof (View)) || type == typeof (View))) .Select (type => new object [] { type }); - public static View CreateInstanceIfNotGeneric (Type type) + /// + /// Creates an instance of a view if it is not a generic type. + /// + /// + /// + public static View? CreateInstanceIfNotGeneric (Type type) { if (type.IsGenericType) { @@ -25,4 +36,144 @@ public static View CreateInstanceIfNotGeneric (Type type) return Activator.CreateInstance (type) as View; } + + /// + /// Gets a list of all view classes. + /// + /// + public static List GetAllViewClasses () + { + return typeof (View).Assembly.GetTypes () + .Where ( + myType => myType is { IsClass: true, IsAbstract: false, IsPublic: true } + && myType.IsSubclassOf (typeof (View)) + ) + .ToList (); + } + + /// + /// Creates a view from a type. + /// + /// The type. + /// The constructor to call. + /// + public static View? CreateViewFromType (Type type, ConstructorInfo ctor) + { + View? viewType = null; + + if (type is { IsGenericType: true, IsTypeDefinition: true }) + { + List gTypes = new (); + + foreach (Type args in type.GetGenericArguments ()) + { + gTypes.Add (typeof (object)); + } + + type = type.MakeGenericType (gTypes.ToArray ()); + + Assert.IsType (type, (View)Activator.CreateInstance (type)!); + } + else + { + ParameterInfo [] paramsInfo = ctor.GetParameters (); + Type paramType; + List pTypes = new (); + + if (type.IsGenericType) + { + foreach (Type args in type.GetGenericArguments ()) + { + paramType = args.GetType (); + + if (args.Name == "T") + { + pTypes.Add (typeof (object)); + } + else + { + AddArguments (paramType, pTypes); + } + } + } + + foreach (ParameterInfo p in paramsInfo) + { + paramType = p.ParameterType; + + if (p.HasDefaultValue) + { + pTypes.Add (p.DefaultValue!); + } + else + { + AddArguments (paramType, pTypes); + } + } + + if (type is { IsGenericType: true, IsTypeDefinition: false }) + { + viewType = Activator.CreateInstance (type) as View; + } + else + { + viewType = (View)ctor.Invoke (pTypes.ToArray ()); + } + + Assert.IsType (type, viewType); + } + + return viewType; + } + + private static void AddArguments (Type paramType, List pTypes) + { + if (paramType == typeof (Rectangle)) + { + pTypes.Add (Rectangle.Empty); + } + else if (paramType == typeof (string)) + { + pTypes.Add (string.Empty); + } + else if (paramType == typeof (int)) + { + pTypes.Add (0); + } + else if (paramType == typeof (bool)) + { + pTypes.Add (true); + } + else if (paramType.Name == "IList") + { + pTypes.Add (new List ()); + } + else if (paramType.Name == "View") + { + var top = new Toplevel (); + var view = new View (); + top.Add (view); + pTypes.Add (view); + } + else if (paramType.Name == "View[]") + { + pTypes.Add (new View [] { }); + } + else if (paramType.Name == "Stream") + { + pTypes.Add (new MemoryStream ()); + } + else if (paramType.Name == "String") + { + pTypes.Add (string.Empty); + } + else if (paramType.Name == "TreeView`1[T]") + { + pTypes.Add (string.Empty); + } + else + { + pTypes.Add (null!); + } + } } diff --git a/Tests/UnitTests/Text/AutocompleteTests.cs b/Tests/UnitTests/Text/AutocompleteTests.cs index 7e8c0e1754..69d230cf56 100644 --- a/Tests/UnitTests/Text/AutocompleteTests.cs +++ b/Tests/UnitTests/Text/AutocompleteTests.cs @@ -1,6 +1,5 @@ using System.Text.RegularExpressions; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.TextTests; @@ -26,87 +25,87 @@ public void CursorLeft_CursorRight_Mouse_Button_Pressed_Does_Not_Show_Popup () for (var i = 0; i < 7; i++) { Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); - top.SetNeedsDraw(); + top.SetNeedsDraw (); Application.RunIteration (ref rs); if (i < 4 || i > 5) { DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This a long line and against TextView.", - output - ); + output + ); } else { DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This a long line and against TextView. and against ", - output - ); + output + ); } } Assert.True ( tv.NewMouseEvent ( - new() { Position = new (6, 0), Flags = MouseFlags.Button1Pressed } + new () { Position = new (6, 0), Flags = MouseFlags.Button1Pressed } ) ); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This a long line and against TextView. and against ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.G)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This ag long line and against TextView. against ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This ag long line and against TextView. against ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This ag long line and against TextView. against ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This ag long line and against TextView.", - output - ); + output + ); for (var i = 0; i < 3; i++) { @@ -115,11 +114,11 @@ This ag long line and against TextView. Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This ag long line and against TextView. against ", - output - ); + output + ); } Assert.True (tv.NewKeyDownEvent (Key.Backspace)); @@ -127,33 +126,33 @@ This ag long line and against TextView. Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This a long line and against TextView. and against ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.N)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This an long line and against TextView. and ", - output - ); + output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); top.SetNeedsDraw (); Application.RunIteration (ref rs); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This an long line and against TextView.", - output - ); + output + ); top.Dispose (); } @@ -257,7 +256,7 @@ public void Test_GenerateSuggestions_Simple () var ac = new TextViewAutocomplete (); ((SingleWordSuggestionGenerator)ac.SuggestionGenerator).AllSuggestions = - new() { "fish", "const", "Cobble" }; + new () { "fish", "const", "Cobble" }; var tv = new TextView (); tv.InsertText ("co"); @@ -285,7 +284,7 @@ public void TestSettingColorSchemeOnAutocomplete () Assert.Same (Colors.ColorSchemes ["Menu"], tv.Autocomplete.ColorScheme); // allocate a new custom scheme - tv.Autocomplete.ColorScheme = new() + tv.Autocomplete.ColorScheme = new () { Normal = new (Color.Black, Color.Blue), Focus = new (Color.Black, Color.Cyan) }; diff --git a/Tests/UnitTests/Text/TextFormatterTests.cs b/Tests/UnitTests/Text/TextFormatterTests.cs index 407bd4a790..d214dffb8d 100644 --- a/Tests/UnitTests/Text/TextFormatterTests.cs +++ b/Tests/UnitTests/Text/TextFormatterTests.cs @@ -1,5 +1,4 @@ using System.Text; -using UnitTests; using UICatalog; using UnitTests; using Xunit.Abstractions; @@ -13,7 +12,6 @@ public class TextFormatterTests public TextFormatterTests (ITestOutputHelper output) { _output = output; } private readonly ITestOutputHelper _output; - public static IEnumerable CMGlyphs => new List { new object [] { $"{Glyphs.LeftBracket} Say Hello 你 {Glyphs.RightBracket}", 16, 15 } }; @@ -3954,22 +3952,22 @@ public void FillRemaining_True_False () Assert.False (tf.FillRemaining); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Test Test long Test long long", - _output); + _output); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000000000000000000 011110000000000000000 011111111100000000000 011111111111111000000 000000000000000000000", - _output, - null, - attrs); + _output, + null, + attrs); tf.FillRemaining = true; @@ -3979,15 +3977,15 @@ Test long attrs [2]); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000000000000000000 011111111111111111110 011111111111111111110 011111111111111111110 000000000000000000000", - _output, - null, - attrs); + _output, + null, + attrs); } [SetupFakeDriver] diff --git a/Tests/UnitTests/UnitTests.csproj b/Tests/UnitTests/UnitTests.csproj index c37dc7cc9b..fa84707494 100644 --- a/Tests/UnitTests/UnitTests.csproj +++ b/Tests/UnitTests/UnitTests.csproj @@ -60,7 +60,6 @@ - diff --git a/Tests/UnitTests/View/Adornment/BorderTests.cs b/Tests/UnitTests/View/Adornment/BorderTests.cs index 42cb210b34..0d0bf676b9 100644 --- a/Tests/UnitTests/View/Adornment/BorderTests.cs +++ b/Tests/UnitTests/View/Adornment/BorderTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; @@ -17,7 +16,7 @@ public void Border_Parent_HasFocus_Title_Uses_FocusAttribute () var view = new View { Title = "A", Height = 2, Width = 5 }; superView.Add (view); - view.Border.Thickness = new (0, 1, 0, 0); + view.Border!.Thickness = new (0, 1, 0, 0); view.Border.LineStyle = LineStyle.Single; view.ColorScheme = new () @@ -838,7 +837,7 @@ public void View_SetBorderStyle () │ ┊ ┊ └─┴┄┘")] [SetupFakeDriver] - public void SuperViewRendersLineCanvas_No_Subviews_AutoJoinsLines (bool superViewRendersLineCanvas, string expected) + public void SuperViewRendersLineCanvas_No_SubViews_AutoJoinsLines (bool superViewRendersLineCanvas, string expected) { View superView = new View () { diff --git a/Tests/UnitTests/View/Adornment/MarginTests.cs b/Tests/UnitTests/View/Adornment/MarginTests.cs index 92495c0194..4efeff432f 100644 --- a/Tests/UnitTests/View/Adornment/MarginTests.cs +++ b/Tests/UnitTests/View/Adornment/MarginTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; @@ -13,7 +12,7 @@ public void Margin_Is_Transparent () ((FakeDriver)Application.Driver!).SetBufferSize (5, 5); var view = new View { Height = 3, Width = 3 }; - view.Margin.Diagnostics = ViewDiagnosticFlags.Thickness; + view.Margin!.Diagnostics = ViewDiagnosticFlags.Thickness; view.Margin.Thickness = new (1); Application.Top = new Toplevel (); diff --git a/Tests/UnitTests/View/Adornment/PaddingTests.cs b/Tests/UnitTests/View/Adornment/PaddingTests.cs index f0bbd32afa..e246d22f68 100644 --- a/Tests/UnitTests/View/Adornment/PaddingTests.cs +++ b/Tests/UnitTests/View/Adornment/PaddingTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; @@ -12,7 +11,7 @@ public void Padding_Uses_Parent_ColorScheme () { ((FakeDriver)Application.Driver!).SetBufferSize (5, 5); var view = new View { Height = 3, Width = 3 }; - view.Padding.Thickness = new (1); + view.Padding!.Thickness = new (1); view.Padding.Diagnostics = ViewDiagnosticFlags.Thickness; view.ColorScheme = new() diff --git a/Tests/UnitTests/View/Adornment/ShadowStyletests.cs b/Tests/UnitTests/View/Adornment/ShadowStyleTests.cs similarity index 72% rename from Tests/UnitTests/View/Adornment/ShadowStyletests.cs rename to Tests/UnitTests/View/Adornment/ShadowStyleTests.cs index 76574dfec9..b0a4e3057f 100644 --- a/Tests/UnitTests/View/Adornment/ShadowStyletests.cs +++ b/Tests/UnitTests/View/Adornment/ShadowStyleTests.cs @@ -124,4 +124,41 @@ public void Visual_Test (ShadowStyle style, string expected) view.Dispose (); Application.ResetState (true); } + + + [Theory] + [InlineData (ShadowStyle.None, 0, 0, 0, 0)] + [InlineData (ShadowStyle.Opaque, 1, 0, 0, 1)] + [InlineData (ShadowStyle.Transparent, 1, 0, 0, 1)] + public void ShadowStyle_Button1Pressed_Causes_Movement (ShadowStyle style, int expectedLeft, int expectedTop, int expectedRight, int expectedBottom) + { + var superView = new View + { + Height = 10, Width = 10 + }; + + View view = new () + { + Width = Dim.Auto (), + Height = Dim.Auto (), + Text = "0123", + HighlightStyle = HighlightStyle.Pressed, + ShadowStyle = style, + CanFocus = true + }; + + superView.Add (view); + superView.BeginInit (); + superView.EndInit (); + + Thickness origThickness = view.Margin!.Thickness; + view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed, Position = new (0, 0) }); + Assert.Equal (new (expectedLeft, expectedTop, expectedRight, expectedBottom), view.Margin.Thickness); + + view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released, Position = new (0, 0) }); + Assert.Equal (origThickness, view.Margin.Thickness); + + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); + } } diff --git a/Tests/UnitTests/View/Draw/AllViewsDrawTests.cs b/Tests/UnitTests/View/Draw/AllViewsDrawTests.cs index 9cbac00b30..99151fdc50 100644 --- a/Tests/UnitTests/View/Draw/AllViewsDrawTests.cs +++ b/Tests/UnitTests/View/Draw/AllViewsDrawTests.cs @@ -1,10 +1,9 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.LayoutTests; -public class AllViewsDrawTests (ITestOutputHelper _output) : TestsAllViews +public class AllViewsDrawTests (ITestOutputHelper output) : TestsAllViews { [Theory] [SetupFakeDriver] // Required for spinner view that wants to register timeouts @@ -19,12 +18,12 @@ public void AllViews_Draw_Does_Not_Layout (Type viewType) if (view == null) { - _output.WriteLine ($"Ignoring {viewType} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } - _output.WriteLine ($"Testing {viewType}"); + output.WriteLine ($"Testing {viewType}"); if (view is IDesignable designable) { @@ -35,10 +34,10 @@ public void AllViews_Draw_Does_Not_Layout (Type viewType) view.DrawComplete += (s, e) => drawCompleteCount++; var layoutStartedCount = 0; - view.SubviewLayout += (s, e) => layoutStartedCount++; + view.SubViewLayout += (s, e) => layoutStartedCount++; var layoutCompleteCount = 0; - view.SubviewsLaidOut += (s, e) => layoutCompleteCount++; + view.SubViewsLaidOut += (s, e) => layoutCompleteCount++; view.SetNeedsLayout (); view.Layout (); diff --git a/Tests/UnitTests/View/Draw/ClearViewportTests.cs b/Tests/UnitTests/View/Draw/ClearViewportTests.cs index 236e66506e..8b13583beb 100644 --- a/Tests/UnitTests/View/Draw/ClearViewportTests.cs +++ b/Tests/UnitTests/View/Draw/ClearViewportTests.cs @@ -1,38 +1,36 @@ #nullable enable using Moq; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; [Trait ("Category", "Output")] -public class ClearViewportTests (ITestOutputHelper _output) +public class ClearViewportTests (ITestOutputHelper output) { public class TestableView : View { public bool TestOnClearingViewport () { return OnClearingViewport (); } - public int OnClearingViewportCalled { get; set; } = 0; - public bool CancelOnClearingViewport { get; set; } + public int OnClearingViewportCalled { get; set; } + public bool CancelOnClearingViewport { get; set; } + protected override bool OnClearingViewport () { OnClearingViewportCalled++; + return CancelOnClearingViewport; } - public int OnClearedViewportCalled { get; set; } = 0; - protected override void OnClearedViewport () - { - OnClearedViewportCalled++; - } + public int OnClearedViewportCalled { get; set; } + protected override void OnClearedViewport () { OnClearedViewportCalled++; } } [Fact] public void DoClearViewport_ViewportIsTransparent_DoesNotClear () { // Arrange - Mock view = new Mock { CallBase = true }; + Mock view = new () { CallBase = true }; view.Object.ViewportSettings = ViewportSettings.Transparent; // Act @@ -47,7 +45,7 @@ public void DoClearViewport_ViewportIsTransparent_DoesNotClear () public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () { // Arrange - Mock view = new Mock { CallBase = true }; + Mock view = new () { CallBase = true }; view.Object.CancelOnClearingViewport = true; // Act @@ -61,7 +59,7 @@ public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () { // Arrange - Mock view = new Mock { CallBase = true }; + Mock view = new () { CallBase = true }; view.Object.ClearingViewport += (sender, e) => e.Cancel = true; // Act @@ -75,7 +73,7 @@ public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () public void DoClearViewport_ClearsViewport () { // Arrange - Mock view = new Mock { CallBase = true }; + Mock view = new () { CallBase = true }; // Act view.Object.DoClearViewport (); @@ -88,7 +86,7 @@ public void DoClearViewport_ClearsViewport () public void DoClearViewport_RaisesClearingViewportEvent () { // Arrange - Mock view = new Mock { CallBase = true }; + Mock view = new () { CallBase = true }; var eventRaised = false; view.Object.ClearingViewport += (sender, e) => eventRaised = true; @@ -115,37 +113,37 @@ public void Clear_ClearsEntireViewport () superView.Add (view); superView.BeginInit (); superView.EndInit (); - superView.LayoutSubviews (); + superView.LayoutSubViews (); superView.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─┐ │X│ └─┘", - _output); + output); // On Draw exit the view is excluded from the clip, so this will do nothing. view.ClearViewport (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─┐ │X│ └─┘", - _output); + output); View.SetClipToScreen (); view.ClearViewport (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─┐ │ │ └─┘", - _output); + output); } [Fact] @@ -165,25 +163,25 @@ public void Clear_WithClearVisibleContentOnly_ClearsVisibleContentOnly () superView.Add (view); superView.BeginInit (); superView.EndInit (); - superView.LayoutSubviews (); + superView.LayoutSubViews (); superView.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─┐ │X│ └─┘", - _output); + output); View.SetClipToScreen (); view.ClearViewport (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─┐ │ │ └─┘", - _output); + output); } [Fact] @@ -194,7 +192,7 @@ public void Clear_Viewport_Can_Use_Driver_AddRune_Or_AddStr_Methods () view.DrawingContent += (s, e) => { - Region savedClip = view.AddViewportToClip (); + Region? savedClip = view.AddViewportToClip (); for (var row = 0; row < view.Viewport.Height; row++) { @@ -228,7 +226,7 @@ public void Clear_Viewport_Can_Use_Driver_AddRune_Or_AddStr_Methods () " ; - Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 20, 10), pos); view.FillRect (view.Viewport); @@ -247,7 +245,7 @@ public void Clear_Viewport_Can_Use_Driver_AddRune_Or_AddStr_Methods () " ; - pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); top.Dispose (); } @@ -259,7 +257,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () view.DrawingContent += (s, e) => { - Region savedClip = view.AddViewportToClip (); + Region? savedClip = view.AddViewportToClip (); for (var row = 0; row < view.Viewport.Height; row++) { @@ -293,7 +291,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () " ; - Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 20, 10), pos); view.FillRect (view.Viewport); @@ -311,7 +309,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () └──────────────────┘ "; - pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); top.Dispose (); } @@ -353,39 +351,39 @@ public void Clear_Does_Not_Spillover_Its_Parent (bool label) } DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" cccccccccccccccccccc", - _output - ); + output + ); Attribute [] attributes = { - Colors.ColorSchemes ["TopLevel"].Normal, - Colors.ColorSchemes ["Base"].Normal, - Colors.ColorSchemes ["Base"].Focus + Colors.ColorSchemes ["TopLevel"]!.Normal, + Colors.ColorSchemes ["Base"]!.Normal, + Colors.ColorSchemes ["Base"]!.Focus }; if (label) { DriverAssert.AssertDriverAttributesAre ( - @" + @" 111111111111111111110 111111111111111111110", - _output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); } else { DriverAssert.AssertDriverAttributesAre ( - @" + @" 222222222222222222220 111111111111111111110", - _output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); } if (label) @@ -398,13 +396,13 @@ Colors.ColorSchemes ["Base"].Focus Application.LayoutAndDraw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 222222222222222222220 111111111111111111110", - _output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); } Application.End (runState); diff --git a/Tests/UnitTests/View/Draw/ClipTests.cs b/Tests/UnitTests/View/Draw/ClipTests.cs index 7eccc918d4..d3d1ed039e 100644 --- a/Tests/UnitTests/View/Draw/ClipTests.cs +++ b/Tests/UnitTests/View/Draw/ClipTests.cs @@ -79,7 +79,7 @@ public void FillRect_Fills_HonorsClip (int x, int y, int width, int height) superView.Add (view); superView.BeginInit (); superView.EndInit (); - superView.LayoutSubviews (); + superView.LayoutSubViews (); superView.Draw (); diff --git a/Tests/UnitTests/View/Draw/DrawTests.cs b/Tests/UnitTests/View/Draw/DrawTests.cs index eed5c35323..fc60b7b9a0 100644 --- a/Tests/UnitTests/View/Draw/DrawTests.cs +++ b/Tests/UnitTests/View/Draw/DrawTests.cs @@ -6,7 +6,7 @@ namespace Terminal.Gui.ViewTests; [Trait ("Category", "Output")] -public class DrawTests (ITestOutputHelper _output) +public class DrawTests (ITestOutputHelper output) { [Fact] @@ -41,9 +41,9 @@ public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two () │豈 │ └────────┘ """; - DriverAssert.AssertDriverContentsWithFrameAre (expectedOutput, _output); + DriverAssert.AssertDriverContentsWithFrameAre (expectedOutput, output); - DriverAssert.AssertDriverContentsAre (expectedOutput, _output); + DriverAssert.AssertDriverContentsAre (expectedOutput, output); // This test has nothing to do with color - removing as it is not relevant and fragile top.Dispose (); @@ -91,7 +91,7 @@ public void Colors_On_TextAlignment_Right_And_Bottom () s t """, - _output + output ); DriverAssert.AssertDriverAttributesAre ( @@ -105,7 +105,7 @@ public void Colors_On_TextAlignment_Right_And_Bottom () 0 0 """, - _output, + output, Application.Driver, Colors.ColorSchemes ["Base"]!.Normal ); @@ -133,7 +133,7 @@ public void Draw_Minimum_Full_Border_With_Empty_Viewport () ┌┐ └┘ """, - _output + output ); } @@ -152,7 +152,7 @@ public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Bottom () view.Draw (); - DriverAssert.AssertDriverContentsWithFrameAre ("──", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("──", output); } [Fact] @@ -176,7 +176,7 @@ public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Left () │ │ """, - _output + output ); } @@ -201,7 +201,7 @@ public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Right () │ │ """, - _output + output ); } @@ -223,7 +223,7 @@ public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Top () DriverAssert.AssertDriverContentsWithFrameAre ( "││", - _output + output ); } @@ -300,7 +300,7 @@ public void Draw_Negative_Viewport_Horizontal_With_New_Lines () 3V 4i """, - _output + output ); content.X = -1; @@ -315,12 +315,12 @@ public void Draw_Negative_Viewport_Horizontal_With_New_Lines () V i """, - _output + output ); content.X = -2; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre (@"", _output); + DriverAssert.AssertDriverContentsWithFrameAre (@"", output); content.X = 0; content.Y = -1; @@ -335,7 +335,7 @@ public void Draw_Negative_Viewport_Horizontal_With_New_Lines () 4i 5e """, - _output + output ); content.Y = -6; @@ -350,7 +350,7 @@ public void Draw_Negative_Viewport_Horizontal_With_New_Lines () 9 0 """, - _output + output ); content.Y = -19; @@ -361,17 +361,17 @@ public void Draw_Negative_Viewport_Horizontal_With_New_Lines () 9 """, - _output + output ); content.Y = -20; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); content.X = -2; content.Y = 0; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); top.Dispose (); } @@ -407,7 +407,7 @@ public void Draw_Negative_Viewport_Horizontal_Without_New_Lines () // BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway??? - top.SubviewsLaidOut += Top_LayoutComplete; + top.SubViewsLaidOut += Top_LayoutComplete; Application.Begin (top); Application.LayoutAndDraw (); @@ -417,7 +417,7 @@ public void Draw_Negative_Viewport_Horizontal_Without_New_Lines () 01234 subVi """, - _output + output ); content.X = -1; @@ -429,7 +429,7 @@ public void Draw_Negative_Viewport_Horizontal_Without_New_Lines () 12345 ubVie """, - _output + output ); content.Y = -1; @@ -440,17 +440,17 @@ public void Draw_Negative_Viewport_Horizontal_Without_New_Lines () ubVie """, - _output + output ); content.Y = -2; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); content.X = -20; content.Y = 0; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); top.Dispose (); return; @@ -507,7 +507,7 @@ public void Draw_Negative_Viewport_Vertical () 3V 4i """, - _output + output ); content.X = -1; @@ -522,12 +522,12 @@ public void Draw_Negative_Viewport_Vertical () V i """, - _output + output ); content.X = -2; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre (@"", _output); + DriverAssert.AssertDriverContentsWithFrameAre (@"", output); content.X = 0; content.Y = -1; @@ -542,7 +542,7 @@ public void Draw_Negative_Viewport_Vertical () 4i 5e """, - _output + output ); content.Y = -6; @@ -557,7 +557,7 @@ public void Draw_Negative_Viewport_Vertical () 9 0 """, - _output + output ); content.Y = -19; @@ -568,17 +568,17 @@ public void Draw_Negative_Viewport_Vertical () 9 """, - _output + output ); content.Y = -20; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); content.X = -2; content.Y = 0; Application.LayoutAndDraw (); - DriverAssert.AssertDriverContentsWithFrameAre ("", _output); + DriverAssert.AssertDriverContentsWithFrameAre ("", output); top.Dispose (); } @@ -591,7 +591,7 @@ public void DrawHotString_NonBmp (string expected) var view = new View { Width = 10, Height = 1 }; view.DrawHotString (expected, Attribute.Default, Attribute.Default); - DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + DriverAssert.AssertDriverContentsWithFrameAre (expected, output); } // TODO: The tests below that use Label should use View instead. @@ -626,9 +626,9 @@ public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two () │𝔹 │ └────────┘ """; - DriverAssert.AssertDriverContentsWithFrameAre (expected, _output); + DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - DriverAssert.AssertDriverContentsAre (expected, _output); + DriverAssert.AssertDriverContentsAre (expected, output); top.Dispose (); // This test has nothing to do with color - removing as it is not relevant and fragile @@ -695,7 +695,7 @@ public void Correct_Redraw_Viewport_NeedDisplay_On_Shrink_And_Move_Down_Right_Us A text with some long width and also with two lines. " , - _output + output ); view.Frame = new (3, 3, 10, 1); @@ -711,7 +711,7 @@ and also with two lines. " A text wit", - _output + output ); Application.End (runState); top.Dispose (); @@ -744,7 +744,7 @@ public void Correct_Redraw_Viewport_NeedDisplay_On_Shrink_And_Move_Down_Right_Us A text with some long width and also with two lines. " , - _output + output ); view.X = 3; @@ -764,7 +764,7 @@ and also with two lines. " A text wit" , - _output + output ); Application.End (runState); top.Dispose (); @@ -796,7 +796,7 @@ public void Correct_Redraw_Viewport_NeedDisplay_On_Shrink_And_Move_Up_Left_Using A text with some long width and also with two lines. " , - _output + output ); view.Frame = new (1, 1, 10, 1); @@ -810,7 +810,7 @@ and also with two lines. " At 0,0 A text wit" , - _output + output ); Application.End (runState); top.Dispose (); @@ -843,7 +843,7 @@ public void Correct_Redraw_Viewport_NeedDisplay_On_Shrink_And_Move_Up_Left_Using A text with some long width and also with two lines. " , - _output + output ); view.X = 1; @@ -862,7 +862,7 @@ and also with two lines. " At 0,0 A text wit" , - _output + output ); Application.End (runState); top.Dispose (); @@ -873,7 +873,7 @@ public class DerivedView : View public bool IsKeyDown { get; set; } public bool IsKeyPress { get; set; } public bool IsKeyUp { get; set; } - public override string Text { get; set; } + public override string Text { get; set; } = null!; protected override bool OnDrawingContent () { diff --git a/Tests/UnitTests/View/Draw/NeedsDrawTests.cs b/Tests/UnitTests/View/Draw/NeedsDrawTests.cs index 21a09589f9..4d2a9af45f 100644 --- a/Tests/UnitTests/View/Draw/NeedsDrawTests.cs +++ b/Tests/UnitTests/View/Draw/NeedsDrawTests.cs @@ -39,13 +39,13 @@ public void Frame_Set_After_Initialize_Update_NeededDisplay () RunState runState = Application.Begin (top); - top.SubviewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDrawRect); }; + top.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDrawRect); }; - frame.SubviewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDrawRect); }; + frame.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDrawRect); }; - label.SubviewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDrawRect); }; + label.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDrawRect); }; - view.SubviewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 13, 1), view._needsDrawRect); }; + view.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 13, 1), view._needsDrawRect); }; Assert.Equal (new (0, 0, 80, 25), top.Frame); Assert.Equal (new (20, 8, 40, 8), frame.Frame); diff --git a/Tests/UnitTests/View/Draw/TransparentTests.cs b/Tests/UnitTests/View/Draw/TransparentTests.cs index 81747914ab..a1f3159f47 100644 --- a/Tests/UnitTests/View/Draw/TransparentTests.cs +++ b/Tests/UnitTests/View/Draw/TransparentTests.cs @@ -1,13 +1,11 @@ #nullable enable -using System.Text; -using UnitTests; using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; [Trait ("Category", "Output")] -public class TransparentTests (ITestOutputHelper _output) +public class TransparentTests (ITestOutputHelper output) { [Fact] [SetupFakeDriver] @@ -50,13 +48,13 @@ public void Transparent_Text_Occludes () ░┌─────────────┐░░░░ ░│Sub░░░░░░░░░░│░░░░ ░└─────────────┘░░░░ -░░░░░░░░░░░░░░░░░░░░", _output); +░░░░░░░░░░░░░░░░░░░░", output); } [Fact] [SetupFakeDriver] - public void Transparent_Subview_Occludes () + public void Transparent_SubView_Occludes () { var super = new View { @@ -104,6 +102,6 @@ public void Transparent_Subview_Occludes () ░┌─────────────┐░░░░ ░│░░░subSub░░░░│░░░░ ░└─────────────┘░░░░ -░░░░░░░░░░░░░░░░░░░░", _output); +░░░░░░░░░░░░░░░░░░░░", output); } } diff --git a/Tests/UnitTests/View/Layout/Dim.Tests.cs b/Tests/UnitTests/View/Layout/Dim.Tests.cs index 5b1698371e..1b0287f803 100644 --- a/Tests/UnitTests/View/Layout/Dim.Tests.cs +++ b/Tests/UnitTests/View/Layout/Dim.Tests.cs @@ -175,7 +175,7 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin w.Width = 200; Assert.True (t.NeedsLayout); w.Height = 200; - t.LayoutSubviews (); + t.LayoutSubViews (); Assert.Equal ("Absolute(200)", w.Width.ToString ()); Assert.Equal ("Absolute(200)", w.Height.ToString ()); diff --git a/Tests/UnitTests/View/Layout/LayoutTests.cs b/Tests/UnitTests/View/Layout/LayoutTests.cs index 46b088394b..1c6d432dbb 100644 --- a/Tests/UnitTests/View/Layout/LayoutTests.cs +++ b/Tests/UnitTests/View/Layout/LayoutTests.cs @@ -1,10 +1,9 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.LayoutTests; -public class LayoutTests (ITestOutputHelper _output) : TestsAllViews +public class LayoutTests (ITestOutputHelper output) : TestsAllViews { [Theory] [SetupFakeDriver] // Required for spinner view that wants to register timeouts @@ -19,7 +18,7 @@ public void AllViews_Layout_Does_Not_Draw (Type viewType) if (view == null) { - _output.WriteLine ($"Ignoring {viewType} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } @@ -33,10 +32,10 @@ public void AllViews_Layout_Does_Not_Draw (Type viewType) view.DrawingContent += (s, e) => drawContentCount++; var layoutStartedCount = 0; - view.SubviewLayout += (s, e) => layoutStartedCount++; + view.SubViewLayout += (s, e) => layoutStartedCount++; var layoutCompleteCount = 0; - view.SubviewsLaidOut += (s, e) => layoutCompleteCount++; + view.SubViewsLaidOut += (s, e) => layoutCompleteCount++; view.SetNeedsLayout (); view.SetNeedsDraw(); diff --git a/Tests/UnitTests/View/Layout/Pos.AnchorEndTests.cs b/Tests/UnitTests/View/Layout/Pos.AnchorEndTests.cs index 75f79af9cc..04afb1dfd2 100644 --- a/Tests/UnitTests/View/Layout/Pos.AnchorEndTests.cs +++ b/Tests/UnitTests/View/Layout/Pos.AnchorEndTests.cs @@ -1,15 +1,9 @@ using UnitTests; -using UnitTests; -using Xunit.Abstractions; -using static Terminal.Gui.Dim; -using static Terminal.Gui.Pos; namespace Terminal.Gui.LayoutTests; -public class PosAnchorEndTests (ITestOutputHelper output) +public class PosAnchorEndTests () { - - // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved // TODO: A new test that calls SetRelativeLayout directly is needed. [Fact] @@ -72,5 +66,4 @@ public void PosAnchorEnd_Equal_Inside_Window () // Application.End (rs); // top.Dispose (); //} - } diff --git a/Tests/UnitTests/View/Layout/Pos.CenterTests.cs b/Tests/UnitTests/View/Layout/Pos.CenterTests.cs index 26b834a220..693c8e3e9f 100644 --- a/Tests/UnitTests/View/Layout/Pos.CenterTests.cs +++ b/Tests/UnitTests/View/Layout/Pos.CenterTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; using static Terminal.Gui.Dim; using static Terminal.Gui.Pos; diff --git a/Tests/UnitTests/View/Layout/Pos.CombineTests.cs b/Tests/UnitTests/View/Layout/Pos.CombineTests.cs index a3b8b50459..58a6c4761a 100644 --- a/Tests/UnitTests/View/Layout/Pos.CombineTests.cs +++ b/Tests/UnitTests/View/Layout/Pos.CombineTests.cs @@ -98,7 +98,7 @@ public void PosCombine_Refs_SuperView_Throws () f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1); f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1); - Application.Top.SubviewsLaidOut += (s, e) => + Application.Top.SubViewsLaidOut += (s, e) => { Assert.Equal (0, Application.Top.Frame.X); Assert.Equal (0, Application.Top.Frame.Y); diff --git a/Tests/UnitTests/View/Mouse/GetViewsUnderMouseTests.cs b/Tests/UnitTests/View/Mouse/GetViewsUnderMouseTests.cs index 474dfa687f..5e900ca5d7 100644 --- a/Tests/UnitTests/View/Mouse/GetViewsUnderMouseTests.cs +++ b/Tests/UnitTests/View/Mouse/GetViewsUnderMouseTests.cs @@ -74,9 +74,9 @@ public void GetViewsUnderMouse_Top_Adornments_Returns_Correct_View ( { Frame = new (frameX, frameY, 10, 10) }; - Application.Top.Margin.Thickness = new (marginThickness); - Application.Top.Border.Thickness = new (borderThickness); - Application.Top.Padding.Thickness = new (paddingThickness); + Application.Top.Margin!.Thickness = new (marginThickness); + Application.Top.Border!.Thickness = new (borderThickness); + Application.Top.Padding!.Thickness = new (paddingThickness); var location = new Point (testX, testY); @@ -120,49 +120,6 @@ public void GetViewsUnderMouse_Returns_Top_If_No_SubViews (int testX, int testY) Application.ResetState (true); } - [Theory] - [InlineData (0, 0)] - [InlineData (2, 1)] - [InlineData (20, 20)] - public void GetViewsUnderMouse_Returns_Null_If_No_SubViews_Coords_Outside (int testX, int testY) - { - // Arrange - var view = new View - { - Frame = new (0, 0, 10, 10) - }; - - var location = new Point (testX, testY); - - // Act - List viewsUnderMouse = View.GetViewsUnderMouse (location); - - // Assert - Assert.Empty (viewsUnderMouse); - } - - [Theory] - [InlineData (0, 0)] - [InlineData (2, 1)] - [InlineData (20, 20)] - public void GetViewsUnderMouse_Returns_Null_If_Start_Not_Visible (int testX, int testY) - { - // Arrange - var view = new View - { - Frame = new (0, 0, 10, 10), - Visible = false - }; - - var location = new Point (testX, testY); - - // Act - List viewsUnderMouse = View.GetViewsUnderMouse (location); - - // Assert - Assert.Empty (viewsUnderMouse); - } - [Theory] [InlineData (0, 0, false)] [InlineData (1, 1, true)] @@ -205,104 +162,6 @@ public void GetViewsUnderMouse_Returns_Correct_If_SubViews (int testX, int testY Application.ResetState (true); } - [Theory] - [InlineData (0, 0, 0, 0, 0, -1, -1, null)] - [InlineData (0, 0, 0, 0, 0, 0, 0, typeof (View))] - [InlineData (0, 0, 0, 0, 0, 1, 1, typeof (View))] - [InlineData (0, 0, 0, 0, 0, 4, 4, typeof (View))] - [InlineData (0, 0, 0, 0, 0, 9, 9, typeof (View))] - [InlineData (0, 0, 0, 0, 0, 10, 10, null)] - [InlineData (1, 1, 0, 0, 0, -1, -1, null)] - [InlineData (1, 1, 0, 0, 0, 0, 0, null)] - [InlineData (1, 1, 0, 0, 0, 1, 1, typeof (View))] - [InlineData (1, 1, 0, 0, 0, 4, 4, typeof (View))] - [InlineData (1, 1, 0, 0, 0, 9, 9, typeof (View))] - [InlineData (1, 1, 0, 0, 0, 10, 10, typeof (View))] - [InlineData (0, 0, 1, 0, 0, -1, -1, null)] - [InlineData (0, 0, 1, 0, 0, 0, 0, typeof (Margin))] - [InlineData (0, 0, 1, 0, 0, 1, 1, typeof (View))] - [InlineData (0, 0, 1, 0, 0, 4, 4, typeof (View))] - [InlineData (0, 0, 1, 0, 0, 9, 9, typeof (Margin))] - [InlineData (0, 0, 1, 0, 0, 10, 10, null)] - [InlineData (0, 0, 1, 1, 0, -1, -1, null)] - [InlineData (0, 0, 1, 1, 0, 0, 0, typeof (Margin))] - [InlineData (0, 0, 1, 1, 0, 1, 1, typeof (Border))] - [InlineData (0, 0, 1, 1, 0, 4, 4, typeof (View))] - [InlineData (0, 0, 1, 1, 0, 9, 9, typeof (Margin))] - [InlineData (0, 0, 1, 1, 0, 10, 10, null)] - [InlineData (0, 0, 1, 1, 1, -1, -1, null)] - [InlineData (0, 0, 1, 1, 1, 0, 0, typeof (Margin))] - [InlineData (0, 0, 1, 1, 1, 1, 1, typeof (Border))] - [InlineData (0, 0, 1, 1, 1, 2, 2, typeof (Padding))] - [InlineData (0, 0, 1, 1, 1, 4, 4, typeof (View))] - [InlineData (0, 0, 1, 1, 1, 9, 9, typeof (Margin))] - [InlineData (0, 0, 1, 1, 1, 10, 10, null)] - [InlineData (1, 1, 1, 0, 0, -1, -1, null)] - [InlineData (1, 1, 1, 0, 0, 0, 0, null)] - [InlineData (1, 1, 1, 0, 0, 1, 1, typeof (Margin))] - [InlineData (1, 1, 1, 0, 0, 4, 4, typeof (View))] - [InlineData (1, 1, 1, 0, 0, 9, 9, typeof (View))] - [InlineData (1, 1, 1, 0, 0, 10, 10, typeof (Margin))] - [InlineData (1, 1, 1, 1, 0, -1, -1, null)] - [InlineData (1, 1, 1, 1, 0, 0, 0, null)] - [InlineData (1, 1, 1, 1, 0, 1, 1, typeof (Margin))] - [InlineData (1, 1, 1, 1, 0, 4, 4, typeof (View))] - [InlineData (1, 1, 1, 1, 0, 9, 9, typeof (Border))] - [InlineData (1, 1, 1, 1, 0, 10, 10, typeof (Margin))] - [InlineData (1, 1, 1, 1, 1, -1, -1, null)] - [InlineData (1, 1, 1, 1, 1, 0, 0, null)] - [InlineData (1, 1, 1, 1, 1, 1, 1, typeof (Margin))] - [InlineData (1, 1, 1, 1, 1, 2, 2, typeof (Border))] - [InlineData (1, 1, 1, 1, 1, 3, 3, typeof (Padding))] - [InlineData (1, 1, 1, 1, 1, 4, 4, typeof (View))] - [InlineData (1, 1, 1, 1, 1, 8, 8, typeof (Padding))] - [InlineData (1, 1, 1, 1, 1, 9, 9, typeof (Border))] - [InlineData (1, 1, 1, 1, 1, 10, 10, typeof (Margin))] - public void Contains ( - int frameX, - int frameY, - int marginThickness, - int borderThickness, - int paddingThickness, - int testX, - int testY, - Type? expectedAdornmentType - ) - { - var view = new View - { - X = frameX, Y = frameY, - Width = 10, Height = 10 - }; - view.Margin.Thickness = new (marginThickness); - view.Border.Thickness = new (borderThickness); - view.Padding.Thickness = new (paddingThickness); - - Type? containedType = null; - - if (view.Contains (new (testX, testY))) - { - containedType = view.GetType (); - } - - if (view.Margin.Contains (new (testX, testY))) - { - containedType = view.Margin.GetType (); - } - - if (view.Border.Contains (new (testX, testY))) - { - containedType = view.Border.GetType (); - } - - if (view.Padding.Contains (new (testX, testY))) - { - containedType = view.Padding.GetType (); - } - - Assert.Equal (expectedAdornmentType, containedType); - } - // Test that GetViewsUnderMouse returns the correct view if the start view has no subviews [Theory] [InlineData (0, 0)] @@ -465,7 +324,7 @@ public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool { Width = 10, Height = 10 }; - Application.Top.Margin.Thickness = new (1); + Application.Top.Margin!.Thickness = new (1); var subview = new View { @@ -523,13 +382,13 @@ public void Returns_Correct_If_Start_Has_Offset_Viewport (int offset, int testX, [InlineData (2, 3, false)] [InlineData (5, 6, false)] [InlineData (6, 7, false)] - public void Returns_Correct_If_Start_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + public void Returns_Correct_If_Start_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { Application.Top = new () { Width = 10, Height = 10 }; - Application.Top.Padding.Thickness = new (1); + Application.Top.Padding!.Thickness = new (1); var subview = new View { @@ -561,9 +420,9 @@ public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Typ { Width = 10, Height = 10 }; - Application.Top.Margin.Thickness = new (1); - Application.Top.Border.Thickness = new (1); - Application.Top.Padding.Thickness = new (1); + Application.Top.Margin!.Thickness = new (1); + Application.Top.Border!.Thickness = new (1); + Application.Top.Padding!.Thickness = new (1); var subview = new View { @@ -601,7 +460,7 @@ public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, boo X = 1, Y = 2, Width = 5, Height = 5 }; - subview.Margin.Thickness = new (1); + subview.Margin!.Thickness = new (1); Application.Top.Add (subview); View? found = View.GetViewsUnderMouse (new (testX, testY)).LastOrDefault (); @@ -622,7 +481,7 @@ public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, boo [InlineData (5, 6, false)] [InlineData (6, 5, false)] [InlineData (5, 5, true)] - public void Returns_Correct_If_SubView_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + public void Returns_Correct_If_SubView_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { Application.Top = new () { @@ -635,25 +494,25 @@ public void Returns_Correct_If_SubView_Has_Adornment_WithSubview (int testX, int X = 1, Y = 1, Width = 5, Height = 5 }; - subview.Padding.Thickness = new (1); + subview.Padding!.Thickness = new (1); // This subview will be at the bottom-right-corner of subview // So screen-relative location will be X + Width - 1 = 5 - var paddingSubview = new View + var paddingSubView = new View { X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1), Width = 1, Height = 1 }; - subview.Padding.Add (paddingSubview); + subview.Padding.Add (paddingSubView); Application.Top.Add (subview); Application.Top.BeginInit (); Application.Top.EndInit (); View? found = View.GetViewsUnderMouse (new (testX, testY)).LastOrDefault (); - Assert.Equal (expectedSubViewFound, found == paddingSubview); + Assert.Equal (expectedSubViewFound, found == paddingSubView); Application.Top.Dispose (); Application.ResetState (true); } @@ -669,7 +528,7 @@ public void Returns_Correct_If_SubView_Has_Adornment_WithSubview (int testX, int [InlineData (5, 6, false)] [InlineData (6, 5, false)] [InlineData (5, 5, true)] - public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { Application.Top = new () { @@ -682,7 +541,7 @@ public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubview X = 1, Y = 1, Width = 5, Height = 5 }; - subview.Padding.Thickness = new (1); + subview.Padding!.Thickness = new (1); // Scroll the subview subview.SetContentSize (new (10, 10)); @@ -690,21 +549,21 @@ public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubview // This subview will be at the bottom-right-corner of subview // So screen-relative location will be X + Width - 1 = 5 - var paddingSubview = new View + var paddingSubView = new View { X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1), Width = 1, Height = 1 }; - subview.Padding.Add (paddingSubview); + subview.Padding.Add (paddingSubView); Application.Top.Add (subview); Application.Top.BeginInit (); Application.Top.EndInit (); View? found = View.GetViewsUnderMouse (new (testX, testY)).LastOrDefault (); - Assert.Equal (expectedSubViewFound, found == paddingSubview); + Assert.Equal (expectedSubViewFound, found == paddingSubView); Application.Top.Dispose (); Application.ResetState (true); } @@ -762,7 +621,7 @@ public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expec [InlineData (2, 2, new [] { "top", "view", "subView" })] [InlineData (3, 3, new [] { "top" })] // clipped [InlineData (2, 3, new [] { "top" })] // clipped - public void GetViewsUnderMouse_Tiled_Subviews (int mouseX, int mouseY, string [] viewIdStrings) + public void GetViewsUnderMouse_Tiled_SubViews (int mouseX, int mouseY, string [] viewIdStrings) { // Arrange Application.Top = new () diff --git a/Tests/UnitTests/View/Mouse/MouseTests.cs b/Tests/UnitTests/View/Mouse/MouseTests.cs index 1c94ecd45f..25bb145996 100644 --- a/Tests/UnitTests/View/Mouse/MouseTests.cs +++ b/Tests/UnitTests/View/Mouse/MouseTests.cs @@ -1,72 +1,10 @@ using UnitTests; -using UnitTests; -using Xunit.Abstractions; namespace Terminal.Gui.ViewMouseTests; [Trait ("Category", "Input")] - -public class MouseTests (ITestOutputHelper output) : TestsAllViews +public class MouseTests : TestsAllViews { - [Theory] - [InlineData (false, false, false)] - [InlineData (true, false, true)] - [InlineData (true, true, true)] - public void MouseClick_SetsFocus_If_CanFocus (bool canFocus, bool setFocus, bool expectedHasFocus) - { - var superView = new View { CanFocus = true, Height = 1, Width = 15 }; - var focusedView = new View { CanFocus = true, Width = 1, Height = 1 }; - var testView = new View { CanFocus = canFocus, X = 4, Width = 4, Height = 1 }; - superView.Add (focusedView, testView); - - focusedView.SetFocus (); - - Assert.True (superView.HasFocus); - Assert.True (focusedView.HasFocus); - Assert.False (testView.HasFocus); - - if (setFocus) - { - testView.SetFocus (); - } - - testView.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }); - Assert.True (superView.HasFocus); - Assert.Equal (expectedHasFocus, testView.HasFocus); - } - - - [Theory] - [InlineData (false, false, 1)] - [InlineData (true, false, 1)] - [InlineData (true, true, 1)] - public void MouseClick_Raises_Selecting (bool canFocus, bool setFocus, int expectedSelectingCount) - { - var superView = new View { CanFocus = true, Height = 1, Width = 15 }; - var focusedView = new View { CanFocus = true, Width = 1, Height = 1 }; - var testView = new View { CanFocus = canFocus, X = 4, Width = 4, Height = 1 }; - superView.Add (focusedView, testView); - - focusedView.SetFocus (); - - Assert.True (superView.HasFocus); - Assert.True (focusedView.HasFocus); - Assert.False (testView.HasFocus); - - if (setFocus) - { - testView.SetFocus (); - } - - int selectingCount = 0; - testView.Selecting += (sender, args) => selectingCount++; - - testView.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }); - Assert.True (superView.HasFocus); - Assert.Equal (expectedSelectingCount, selectingCount); - } - - // TODO: Add more tests that ensure the above test works with positive adornments // Test drag to move @@ -76,13 +14,10 @@ public void MouseClick_Raises_Selecting (bool canFocus, bool setFocus, int expec [InlineData (1, 0, 0, 4, false)] [InlineData (0, 1, 0, 4, true)] [InlineData (0, 0, 1, 4, false)] - [InlineData (1, 1, 0, 3, false)] [InlineData (1, 1, 0, 4, false)] [InlineData (1, 1, 0, 5, true)] [InlineData (1, 1, 0, 6, false)] - - [InlineData (1, 1, 0, 11, false)] [InlineData (1, 1, 0, 12, true)] [InlineData (1, 1, 0, 13, false)] @@ -106,98 +41,19 @@ public void ButtonPressed_In_Border_Starts_Drag (int marginThickness, int border var top = new Toplevel (); top.Add (testView); - var rs = Application.Begin (top); + RunState rs = Application.Begin (top); Assert.Equal (4, testView.Frame.X); - Assert.Equal (new Point (4, 4), testView.Frame.Location); + Assert.Equal (new (4, 4), testView.Frame.Location); Application.RaiseMouseEvent (new () { ScreenPosition = new (xy, xy), Flags = MouseFlags.Button1Pressed }); Application.RaiseMouseEvent (new () { ScreenPosition = new (xy + 1, xy + 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); - Application.RunIteration(ref rs, false); + Application.RunIteration (ref rs); Assert.Equal (expectedMoved, new Point (5, 5) == testView.Frame.Location); top.Dispose (); } - [Theory] - [InlineData (MouseFlags.WheeledUp | MouseFlags.ButtonCtrl, MouseFlags.WheeledLeft)] - [InlineData (MouseFlags.WheeledDown | MouseFlags.ButtonCtrl, MouseFlags.WheeledRight)] - public void WheeledLeft_WheeledRight (MouseFlags mouseFlags, MouseFlags expectedMouseFlagsFromEvent) - { - MouseFlags mouseFlagsFromEvent = MouseFlags.None; - var view = new View (); - view.MouseEvent += (s, e) => mouseFlagsFromEvent = e.Flags; - - view.NewMouseEvent (new MouseEventArgs () { Flags = mouseFlags }); - Assert.Equal (mouseFlagsFromEvent, expectedMouseFlagsFromEvent); - } - - [Fact] - public void NewMouseEvent_Invokes_MouseEvent_Properly () - { - View view = new () - { - Width = 1, - Height = 1, - }; - bool mouseEventInvoked = false; - view.MouseEvent += (s, e) => - { - mouseEventInvoked = true; - e.Handled = true; - }; - - MouseEventArgs me = new (); - view.NewMouseEvent (me); - Assert.True (mouseEventInvoked); - Assert.True (me.Handled); - - view.Dispose (); - } - - [Theory] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - [MemberData (nameof (AllViewTypes))] - public void AllViews_NewMouseEvent_Enabled_False_Does_Not_Set_Handled (Type viewType) - { - var view = CreateInstanceIfNotGeneric (viewType); - - if (view == null) - { - output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - return; - } - - view.Enabled = false; - var me = new MouseEventArgs (); - view.NewMouseEvent (me); - Assert.False (me.Handled); - view.Dispose (); - } - - [Theory] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - [MemberData (nameof (AllViewTypes))] - public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (Type viewType) - { - var view = CreateInstanceIfNotGeneric (viewType); - - if (view == null) - { - output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - return; - } - - view.Enabled = false; - var me = new MouseEventArgs () - { - Flags = MouseFlags.Button1Clicked - }; - view.NewMouseEvent (me); - Assert.False (me.Handled); - view.Dispose (); - } - [Theory] [InlineData (MouseFlags.Button1Pressed, MouseFlags.Button1Released, MouseFlags.Button1Clicked)] [InlineData (MouseFlags.Button2Pressed, MouseFlags.Button2Released, MouseFlags.Button2Clicked)] @@ -207,7 +63,7 @@ public void WantContinuousButtonPressed_False_Button_Press_Release_DoesNotClick { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -238,8 +94,10 @@ public void WantContinuousButtonPressed_False_Button_Press_Release_DoesNotClick Assert.Equal (1, clickedCount); view.Dispose (); - } + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); + } [Theory] [InlineData (MouseFlags.Button1Clicked)] @@ -250,7 +108,7 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_MouseClick (M { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -266,8 +124,10 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_MouseClick (M Assert.Equal (1, clickedCount); view.Dispose (); - } + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); + } [Theory] [InlineData (MouseFlags.Button1Clicked)] @@ -278,7 +138,7 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_Selecting (Mo { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -294,6 +154,9 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_Selecting (Mo Assert.Equal (1, selectingCount); view.Dispose (); + + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); } [Theory] @@ -305,7 +168,7 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -332,6 +195,9 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B Assert.Equal (1, clickedCount); view.Dispose (); + + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); } [Theory] @@ -339,11 +205,15 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B [InlineData (MouseFlags.Button2Pressed, MouseFlags.Button2Released, MouseFlags.Button2Clicked)] [InlineData (MouseFlags.Button3Pressed, MouseFlags.Button3Released, MouseFlags.Button3Clicked)] [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released, MouseFlags.Button4Clicked)] - public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Button_Press_Release_Clicks_Repeatedly (MouseFlags pressed, MouseFlags released, MouseFlags clicked) + public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Button_Press_Release_Clicks_Repeatedly ( + MouseFlags pressed, + MouseFlags released, + MouseFlags clicked + ) { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -375,7 +245,9 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B Assert.Equal (1, clickedCount); view.Dispose (); - Application.ResetState (ignoreDisposed: true); + + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); } [Fact] @@ -383,7 +255,7 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_M { var me = new MouseEventArgs (); - var view = new View () + var view = new View { Width = 1, Height = 1, @@ -417,7 +289,9 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_M me.Handled = false; view.Dispose (); - Application.ResetState (ignoreDisposed: true); + + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); } [Theory] @@ -425,7 +299,7 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_M [InlineData (HighlightStyle.Pressed | HighlightStyle.PressedOutside, 1, 1)] public void HighlightOnPress_Fires_Events_And_Highlights (HighlightStyle highlightOnPress, int expectedEnabling, int expectedDisabling) { - var view = new View () + var view = new View { CanFocus = true, HighlightStyle = highlightOnPress, @@ -433,13 +307,13 @@ public void HighlightOnPress_Fires_Events_And_Highlights (HighlightStyle highlig Width = 1 }; - int enablingHighlight = 0; - int disablingHighlight = 0; - view.Highlight += View_Highlight; - view.ColorScheme = new ColorScheme (new Attribute (ColorName16.Red, ColorName16.Blue)); + var enablingHighlight = 0; + var disablingHighlight = 0; + view.Highlight += ViewHighlight; + view.ColorScheme = new (new Attribute (ColorName16.Red, ColorName16.Blue)); ColorScheme originalColorScheme = view.ColorScheme; - view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed, }); + view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed }); if (highlightOnPress != HighlightStyle.None) { @@ -450,16 +324,19 @@ public void HighlightOnPress_Fires_Events_And_Highlights (HighlightStyle highlig Assert.Equal (originalColorScheme, view.ColorScheme); } - view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released, }); + view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released }); Assert.Equal (originalColorScheme, view.ColorScheme); Assert.Equal (expectedEnabling, enablingHighlight); Assert.Equal (expectedDisabling, disablingHighlight); view.Dispose (); + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); + return; - void View_Highlight (object sender, CancelEventArgs e) + void ViewHighlight (object sender, CancelEventArgs e) { if (e.NewValue == HighlightStyle.None) { @@ -480,16 +357,16 @@ void View_Highlight (object sender, CancelEventArgs e) [InlineData (10)] public void HighlightOnPress_Move_Keeps_Highlight (int x) { - var view = new View () + var view = new View { CanFocus = true, HighlightStyle = HighlightStyle.Pressed | HighlightStyle.PressedOutside, Height = 1, Width = 1 }; - int enablingHighlight = 0; - int disablingHighlight = 0; - view.Highlight += View_Highlight; + var enablingHighlight = 0; + var disablingHighlight = 0; + view.Highlight += ViewHighlight; bool inViewport = view.Viewport.Contains (x, 0); // Start at 0,0 ; in viewport @@ -513,6 +390,7 @@ public void HighlightOnPress_Move_Keeps_Highlight (int x) // Move backto 0,0 ; in viewport view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed }); + if (inViewport) { Assert.Equal (3, enablingHighlight); @@ -526,9 +404,12 @@ public void HighlightOnPress_Move_Keeps_Highlight (int x) view.Dispose (); + // Button1Pressed, Button1Released cause Application.MouseGrabView to be set + Application.ResetState (true); + return; - void View_Highlight (object sender, CancelEventArgs e) + void ViewHighlight (object sender, CancelEventArgs e) { if (e.NewValue == HighlightStyle.None) { @@ -540,6 +421,4 @@ void View_Highlight (object sender, CancelEventArgs e) } } } - - } diff --git a/Tests/UnitTests/View/Navigation/CanFocusTests.cs b/Tests/UnitTests/View/Navigation/CanFocusTests.cs index 88bd8300a2..7b48b6b1dc 100644 --- a/Tests/UnitTests/View/Navigation/CanFocusTests.cs +++ b/Tests/UnitTests/View/Navigation/CanFocusTests.cs @@ -1,211 +1,9 @@ using UnitTests; -using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; -public class CanFocusTests () : TestsAllViews +public class CanFocusTests { - [Fact] - public void CanFocus_False_Prevents_SubSubView_HasFocus () - { - var view = new View { }; - var subView = new View { }; - var subSubView = new View { CanFocus = true }; - - subView.Add (subSubView); - view.Add (subView); - - Assert.False (view.CanFocus); - Assert.False (subView.CanFocus); - Assert.True (subSubView.CanFocus); - - view.SetFocus (); - Assert.False (view.HasFocus); - - subView.SetFocus (); - Assert.False (subView.HasFocus); - - subSubView.SetFocus (); - Assert.False (subSubView.HasFocus); - } - - [Fact] - public void CanFocus_False_Prevents_SubView_HasFocus () - { - var view = new View { }; - var subView = new View { CanFocus = true }; - var subSubView = new View { }; - - subView.Add (subSubView); - view.Add (subView); - - Assert.False (view.CanFocus); - Assert.True (subView.CanFocus); - Assert.False (subSubView.CanFocus); - - view.SetFocus (); - Assert.False (view.HasFocus); - - subView.SetFocus (); - Assert.False (subView.HasFocus); - - subSubView.SetFocus (); - Assert.False (subSubView.HasFocus); - } - - [Fact] - public void CanFocus_Set_True_No_SuperView_Doesnt_Set_HasFocus () - { - var view = new View { }; - - // Act - view.CanFocus = true; - Assert.False (view.HasFocus); - } - - [Fact] - public void CanFocus_Set_True_Sets_HasFocus_To_True () - { - var view = new View { }; - var subView = new View { }; - view.Add (subView); - - Assert.False (view.CanFocus); - Assert.False (subView.CanFocus); - - view.SetFocus (); - Assert.False (view.HasFocus); - Assert.False (subView.HasFocus); - - view.CanFocus = true; - view.SetFocus (); - Assert.True (view.HasFocus); - - // Act - subView.CanFocus = true; - Assert.True (subView.HasFocus); - } - - [Fact] - public void CanFocus_Set_SubView_True_Sets_HasFocus_To_True () - { - var view = new View - { - CanFocus = true - }; - var subView = new View - { - CanFocus = false - }; - var subSubView = new View - { - CanFocus = true - }; - - subView.Add (subSubView); - view.Add (subView); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.False (subView.HasFocus); - Assert.False (subSubView.HasFocus); - - // Act - subView.CanFocus = true; - Assert.True (subView.HasFocus); - Assert.True (subSubView.HasFocus); - } - - - [Fact] - public void CanFocus_Set_SubView_True_Does_Not_Change_Focus_If_SuperView_Focused_Is_True () - { - var top = new View - { - Id = "top", - CanFocus = true - }; - var subView = new View - { - Id = "subView", - CanFocus = true - }; - var subSubView = new View - { - Id = "subSubView", - CanFocus = true - }; - - subView.Add (subSubView); - - var subView2 = new View - { - Id = "subView2", - CanFocus = false - }; - - top.Add (subView, subView2); - - top.SetFocus (); - Assert.True (top.HasFocus); - Assert.Equal (subView, top.Focused); - Assert.True (subView.HasFocus); - Assert.True (subSubView.HasFocus); - - // Act - subView2.CanFocus = true; - Assert.False (subView2.HasFocus); - Assert.True (subView.HasFocus); - Assert.True (subSubView.HasFocus); - } - - [Fact] - public void CanFocus_Set_False_Sets_HasFocus_To_False () - { - var view = new View { CanFocus = true }; - var view2 = new View { CanFocus = true }; - view2.Add (view); - - Assert.True (view.CanFocus); - - view.SetFocus (); - Assert.True (view.HasFocus); - - view.CanFocus = false; - Assert.False (view.CanFocus); - Assert.False (view.HasFocus); - } - - // TODO: Figure out what this test is supposed to be testing - [Fact] - public void CanFocus_Faced_With_Container () - { - var t = new Toplevel (); - var w = new Window (); - var f = new FrameView (); - var v = new View { CanFocus = true }; - f.Add (v); - w.Add (f); - t.Add (w); - - Assert.True (t.CanFocus); - Assert.True (w.CanFocus); - Assert.True (f.CanFocus); - Assert.True (v.CanFocus); - - f.CanFocus = false; - Assert.False (f.CanFocus); - Assert.True (v.CanFocus); - - v.CanFocus = false; - Assert.False (f.CanFocus); - Assert.False (v.CanFocus); - - v.CanFocus = true; - Assert.False (f.CanFocus); - Assert.True (v.CanFocus); - } - // TODO: Figure out what this test is supposed to be testing [Fact] public void CanFocus_Faced_With_Container_Before_Run () @@ -288,38 +86,6 @@ public void CanFocus_Faced_With_Container_Before_Run () // r.Dispose (); //} - [Fact] - public void CanFocus_True_Focuses () - { - View view = new () - { - Id = "view" - }; - - View superView = new () - { - Id = "superView", - CanFocus = true - }; - - superView.Add (view); - - superView.SetFocus (); - Assert.True (superView.HasFocus); - Assert.NotEqual (view, superView.Focused); - - view.CanFocus = true; - Assert.True (superView.HasFocus); - Assert.Equal (view, superView.Focused); - Assert.True (view.HasFocus); - - view.CanFocus = false; - Assert.True (superView.HasFocus); - Assert.NotEqual (view, superView.Focused); - Assert.False (view.HasFocus); - } - - [Fact] public void CanFocus_Set_True_Get_AdvanceFocus_Works () { diff --git a/Tests/UnitTests/View/Navigation/EnabledTests.cs b/Tests/UnitTests/View/Navigation/EnabledTests.cs index 46f8a782b8..8cd3517d1d 100644 --- a/Tests/UnitTests/View/Navigation/EnabledTests.cs +++ b/Tests/UnitTests/View/Navigation/EnabledTests.cs @@ -1,261 +1,13 @@ using UnitTests; -using UnitTests; -using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; -public class EnabledTests () : TestsAllViews +public class EnabledTests { - [Fact] - public void Enabled_False_Leaves () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - view.SetFocus (); - Assert.True (view.HasFocus); - - view.Enabled = false; - Assert.False (view.HasFocus); - } - - [Fact] - public void Enabled_False_Leaves_Subview () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true - }; - - view.Add (subView); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - - view.Enabled = false; - Assert.False (view.HasFocus); - Assert.False (subView.HasFocus); - } - - [Fact] - public void Enabled_False_Leaves_Subview2 () - { - var view = new Window - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true - }; - - view.Add (subView); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - - view.Enabled = false; - Assert.False (view.HasFocus); - Assert.False (subView.HasFocus); - } - - [Fact] - public void Enabled_False_On_Subview_Leaves_Just_Subview () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true - }; - - view.Add (subView); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - - subView.Enabled = false; - Assert.True (view.HasFocus); - Assert.False (subView.HasFocus); - } - - [Fact] - public void Enabled_False_Focuses_Deepest_Focusable_Subview () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true - }; - - var subViewSubView1 = new View - { - Id = "subViewSubView1", - CanFocus = false - }; - - var subViewSubView2 = new View - { - Id = "subViewSubView2", - CanFocus = true - }; - - var subViewSubView3 = new View - { - Id = "subViewSubView3", - CanFocus = true // This is the one that will be focused - }; - subView.Add (subViewSubView1, subViewSubView2, subViewSubView3); - - view.Add (subView); - - view.SetFocus (); - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - Assert.Equal (subViewSubView2, subView.Focused); - - subViewSubView2.Enabled = false; - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - Assert.Equal (subViewSubView3, subView.Focused); - Assert.True (subViewSubView3.HasFocus); - } - - [Fact] - public void Enabled_True_Subview_Focuses_SubView () - { - var view = new View - { - Id = "view", - CanFocus = true, - Enabled = false - }; - - var subView = new View - { - Id = "subView", - CanFocus = true - }; - - view.Add (subView); - - view.SetFocus (); - Assert.False (view.HasFocus); - Assert.False (subView.HasFocus); - - view.Enabled = true; - Assert.True (view.HasFocus); - Assert.True (subView.HasFocus); - } - - [Fact] - public void Enabled_True_On_Subview_Focuses () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true, - Enabled = false - }; - - view.Add (subView); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.False (subView.HasFocus); - - subView.Enabled = true; - Assert.True (view.HasFocus); - Assert.True (subView.HasFocus); - } - - [Fact] - public void Enabled_True_Focuses_Deepest_Focusable_Subview () - { - var view = new View - { - Id = "view", - CanFocus = true - }; - - var subView = new View - { - Id = "subView", - CanFocus = true, - Enabled = false - }; - - var subViewSubView1 = new View - { - Id = "subViewSubView1", - CanFocus = false - }; - - var subViewSubView2 = new View - { - Id = "subViewSubView2", - CanFocus = true // This is the one that will be focused - }; - - var subViewSubView3 = new View - { - Id = "subViewSubView3", - CanFocus = true - }; - subView.Add (subViewSubView1, subViewSubView2, subViewSubView3); - - view.Add (subView); - - view.SetFocus (); - Assert.False (subView.HasFocus); - Assert.False (subViewSubView2.HasFocus); - - subView.Enabled = true; - Assert.True (subView.HasFocus); - Assert.Equal (subView, view.Focused); - Assert.Equal (subViewSubView2, subView.Focused); - Assert.True (subViewSubView2.HasFocus); - } - + [Fact] [AutoInitShutdown] - public void _Enabled_Sets_Also_Sets_Subviews () + public void _Enabled_Sets_Also_Sets_SubViews () { var wasClicked = false; var button = new Button { Text = "Click Me" }; diff --git a/Tests/UnitTests/View/Navigation/NavigationTests.cs b/Tests/UnitTests/View/Navigation/NavigationTests.cs index d720676634..ec22f749a3 100644 --- a/Tests/UnitTests/View/Navigation/NavigationTests.cs +++ b/Tests/UnitTests/View/Navigation/NavigationTests.cs @@ -1,11 +1,9 @@ -using JetBrains.Annotations; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; -public class NavigationTests (ITestOutputHelper _output) : TestsAllViews +public class NavigationTests (ITestOutputHelper output) : TestsAllViews { [Theory] [MemberData (nameof (AllViewTypes))] @@ -16,22 +14,21 @@ public void AllViews_AtLeastOneNavKey_Advances (Type viewType) if (view == null) { - _output.WriteLine ($"Ignoring {viewType} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } if (!view.CanFocus) { - _output.WriteLine ($"Ignoring {viewType} - It can't focus."); + output.WriteLine ($"Ignoring {viewType} - It can't focus."); return; } - Toplevel top = new (); Application.Top = top; - Application.Navigation = new ApplicationNavigation (); + Application.Navigation = new (); View otherView = new () { @@ -68,6 +65,7 @@ public void AllViews_AtLeastOneNavKey_Advances (Type viewType) // Try once more (HexView) Application.RaiseKeyDownEvent (key); } + break; default: Application.RaiseKeyDownEvent (Key.Tab); @@ -78,12 +76,12 @@ public void AllViews_AtLeastOneNavKey_Advances (Type viewType) if (!view.HasFocus) { left = true; - _output.WriteLine ($"{view.GetType ().Name} - {key} Left."); + output.WriteLine ($"{view.GetType ().Name} - {key} Left."); break; } - _output.WriteLine ($"{view.GetType ().Name} - {key} did not Leave."); + output.WriteLine ($"{view.GetType ().Name} - {key} did not Leave."); } top.Dispose (); @@ -101,28 +99,28 @@ public void AllViews_HasFocus_Changed_Event (Type viewType) if (view == null) { - _output.WriteLine ($"Ignoring {viewType} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } if (!view.CanFocus) { - _output.WriteLine ($"Ignoring {viewType} - It can't focus."); + output.WriteLine ($"Ignoring {viewType} - It can't focus."); return; } if (view is Toplevel && ((Toplevel)view).Modal) { - _output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); + output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); return; } Toplevel top = new (); Application.Top = top; - Application.Navigation = new ApplicationNavigation (); + Application.Navigation = new (); View otherView = new () { @@ -135,16 +133,16 @@ public void AllViews_HasFocus_Changed_Event (Type viewType) var hasFocusFalse = 0; view.HasFocusChanged += (s, e) => - { - if (e.NewValue) - { - hasFocusTrue++; - } - else - { - hasFocusFalse++; - } - }; + { + if (e.NewValue) + { + hasFocusTrue++; + } + else + { + hasFocusFalse++; + } + }; top.Add (view, otherView); Assert.False (view.HasFocus); @@ -185,7 +183,10 @@ public void AllViews_HasFocus_Changed_Event (Type viewType) // Try another nav key (e.g. for TextView that eats Tab) Application.RaiseKeyDownEvent (Key.CursorDown); } - }; + } + + ; + break; case TabBehavior.TabGroup: @@ -263,21 +264,21 @@ public void AllViews_Visible_False_No_HasFocus_Events (Type viewType) if (view == null) { - _output.WriteLine ($"Ignoring {viewType} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } if (!view.CanFocus) { - _output.WriteLine ($"Ignoring {viewType} - It can't focus."); + output.WriteLine ($"Ignoring {viewType} - It can't focus."); return; } if (view is Toplevel && ((Toplevel)view).Modal) { - _output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); + output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); return; } @@ -285,7 +286,7 @@ public void AllViews_Visible_False_No_HasFocus_Events (Type viewType) Toplevel top = new (); Application.Top = top; - Application.Navigation = new ApplicationNavigation (); + Application.Navigation = new (); View otherView = new () { @@ -321,66 +322,8 @@ public void AllViews_Visible_False_No_HasFocus_Events (Type viewType) top.Dispose (); Application.ResetState (); - } - // View.Focused & View.MostFocused tests - - // View.Focused - No subviews - [Fact] - public void Focused_NoSubviews () - { - var view = new View (); - Assert.Null (view.Focused); - - view.CanFocus = true; - view.SetFocus (); - } - - [Fact] - public void GetMostFocused_NoSubviews_Returns_Null () - { - var view = new View (); - Assert.Null (view.Focused); - - view.CanFocus = true; - Assert.False (view.HasFocus); - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.Null (view.MostFocused); - } - - [Fact] - public void GetMostFocused_Returns_Most () - { - var view = new View () - { - Id = "view", - CanFocus = true - }; - - var subview = new View () - { - Id = "subview", - CanFocus = true - }; - - view.Add (subview); - - view.SetFocus (); - Assert.True (view.HasFocus); - Assert.True (subview.HasFocus); - Assert.Equal (subview, view.MostFocused); - - var subview2 = new View () - { - Id = "subview2", - CanFocus = true - }; - - view.Add (subview2); - Assert.Equal (subview2, view.MostFocused); - } [Fact] [SetupFakeDriver] @@ -403,7 +346,6 @@ public void Navigation_With_Null_Focused_View () Application.Shutdown (); } - [Fact] [AutoInitShutdown] public void Application_Begin_FocusesDeepest () diff --git a/Tests/UnitTests/View/SubviewTests.cs b/Tests/UnitTests/View/SubviewTests.cs index 666a282e01..bfedabe573 100644 --- a/Tests/UnitTests/View/SubviewTests.cs +++ b/Tests/UnitTests/View/SubviewTests.cs @@ -1,202 +1,14 @@ -using System.Text; -using UnitTests; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; -public class SubviewTests +public class SubViewTests { private readonly ITestOutputHelper _output; - public SubviewTests (ITestOutputHelper output) { _output = output; } + public SubViewTests (ITestOutputHelper output) { _output = output; } + // TODO: This is a poor unit tests. Not clear what it's testing. Refactor. [Fact] - [AutoInitShutdown] - public void GetTopSuperView_Test () - { - var v1 = new View (); - var fv1 = new FrameView (); - fv1.Add (v1); - var tf1 = new TextField (); - var w1 = new Window (); - w1.Add (fv1, tf1); - var top1 = new Toplevel (); - top1.Add (w1); - - var v2 = new View (); - var fv2 = new FrameView (); - fv2.Add (v2); - var tf2 = new TextField (); - var w2 = new Window (); - w2.Add (fv2, tf2); - var top2 = new Toplevel (); - top2.Add (w2); - - Assert.Equal (top1, v1.GetTopSuperView ()); - Assert.Equal (top2, v2.GetTopSuperView ()); - - v1.Dispose (); - fv1.Dispose (); - tf1.Dispose (); - w1.Dispose (); - top1.Dispose (); - v2.Dispose (); - fv2.Dispose (); - tf2.Dispose (); - w2.Dispose (); - top2.Dispose (); - } - - [Fact] - [TestRespondersDisposed] - public void Initialized_Event_Comparing_With_Added_Event () - { - Application.Init (new FakeDriver ()); - - var top = new Toplevel { Id = "0" }; // Frame: 0, 0, 80, 25; Viewport: 0, 0, 80, 25 - - var winAddedToTop = new Window - { - Id = "t", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 0, 0, 80, 25; Viewport: 0, 0, 78, 23 - - var v1AddedToWin = new View - { - Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (because Windows has a border) - - var v2AddedToWin = new View - { - Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (because Windows has a border) - - var svAddedTov1 = new View - { - Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (same as it's superview v1AddedToWin) - - int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; - - winAddedToTop.Added += (s, e) => - { - Assert.Equal (e.SuperView.Frame.Width, winAddedToTop.Frame.Width); - Assert.Equal (e.SuperView.Frame.Height, winAddedToTop.Frame.Height); - }; - - v1AddedToWin.Added += (s, e) => - { - Assert.Equal (e.SuperView.Frame.Width, v1AddedToWin.Frame.Width); - Assert.Equal (e.SuperView.Frame.Height, v1AddedToWin.Frame.Height); - }; - - v2AddedToWin.Added += (s, e) => - { - Assert.Equal (e.SuperView.Frame.Width, v2AddedToWin.Frame.Width); - Assert.Equal (e.SuperView.Frame.Height, v2AddedToWin.Frame.Height); - }; - - svAddedTov1.Added += (s, e) => - { - Assert.Equal (e.SuperView.Frame.Width, svAddedTov1.Frame.Width); - Assert.Equal (e.SuperView.Frame.Height, svAddedTov1.Frame.Height); - }; - - top.Initialized += (s, e) => - { - tc++; - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (1, sv1c); - - Assert.True (top.CanFocus); - Assert.True (winAddedToTop.CanFocus); - Assert.False (v1AddedToWin.CanFocus); - Assert.False (v2AddedToWin.CanFocus); - Assert.False (svAddedTov1.CanFocus); - - Application.LayoutAndDraw (); - }; - - winAddedToTop.Initialized += (s, e) => - { - wc++; - Assert.Equal (top.Viewport.Width, winAddedToTop.Frame.Width); - Assert.Equal (top.Viewport.Height, winAddedToTop.Frame.Height); - }; - - v1AddedToWin.Initialized += (s, e) => - { - v1c++; - - // Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the v1AddedToWin.Frame be the same as the Top.Frame/Viewport - // as it is a subview of winAddedToTop, which has a border! - //Assert.Equal (top.Viewport.Width, v1AddedToWin.Frame.Width); - //Assert.Equal (top.Viewport.Height, v1AddedToWin.Frame.Height); - }; - - v2AddedToWin.Initialized += (s, e) => - { - v2c++; - - // Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the v2AddedToWin.Frame be the same as the Top.Frame/Viewport - // as it is a subview of winAddedToTop, which has a border! - //Assert.Equal (top.Viewport.Width, v2AddedToWin.Frame.Width); - //Assert.Equal (top.Viewport.Height, v2AddedToWin.Frame.Height); - }; - - svAddedTov1.Initialized += (s, e) => - { - sv1c++; - - // Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the svAddedTov1.Frame be the same as the Top.Frame/Viewport - // because sv1AddedTov1 is a subview of v1AddedToWin, which is a subview of - // winAddedToTop, which has a border! - //Assert.Equal (top.Viewport.Width, svAddedTov1.Frame.Width); - //Assert.Equal (top.Viewport.Height, svAddedTov1.Frame.Height); - Assert.False (svAddedTov1.CanFocus); - //Assert.Throws (() => svAddedTov1.CanFocus = true); - Assert.False (svAddedTov1.CanFocus); - }; - - v1AddedToWin.Add (svAddedTov1); - winAddedToTop.Add (v1AddedToWin, v2AddedToWin); - top.Add (winAddedToTop); - - Application.Iteration += (s, a) => - { - Application.LayoutAndDraw (); - top.Running = false; - }; - - Application.Run (top); - top.Dispose (); - Application.Shutdown (); - - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (1, sv1c); - - Assert.True (top.CanFocus); - Assert.True (winAddedToTop.CanFocus); - Assert.False (v1AddedToWin.CanFocus); - Assert.False (v2AddedToWin.CanFocus); - Assert.False (svAddedTov1.CanFocus); - - v1AddedToWin.CanFocus = true; - Assert.False (svAddedTov1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1. - } - - [Fact] - [TestRespondersDisposed] public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () { Application.Init (new FakeDriver ()); @@ -261,6 +73,7 @@ public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () Assert.NotEqual (t.Frame.Width, sv1.Frame.Width); Assert.NotEqual (t.Frame.Height, sv1.Frame.Height); Assert.False (sv1.CanFocus); + //Assert.Throws (() => sv1.CanFocus = true); Assert.False (sv1.CanFocus); }; @@ -285,4 +98,5 @@ public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () Assert.True (w.CanFocus); Assert.False (v1.CanFocus); Assert.False (v2.CanFocus); - }} + } +} diff --git a/Tests/UnitTests/View/TextTests.cs b/Tests/UnitTests/View/TextTests.cs index 6370521ec4..f680e2b740 100644 --- a/Tests/UnitTests/View/TextTests.cs +++ b/Tests/UnitTests/View/TextTests.cs @@ -1,7 +1,4 @@ -using System.Runtime.CompilerServices; -using System.Text; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; @@ -11,7 +8,6 @@ namespace Terminal.Gui.ViewTests; /// public class TextTests (ITestOutputHelper output) { - [Fact] [SetupFakeDriver] public void Setting_With_Height_Horizontal () @@ -27,7 +23,7 @@ public void Setting_With_Height_Horizontal () Assert.Equal (new (0, 0, 5, 1), label.Frame); - top.LayoutSubviews (); + top.LayoutSubViews (); top.Draw (); var expected = @" @@ -42,7 +38,7 @@ public void Setting_With_Height_Horizontal () Assert.Equal (new (0, 0, 10, 2), label.Frame); - top.LayoutSubviews (); + top.LayoutSubViews (); View.SetClipToScreen (); top.Draw (); @@ -459,7 +455,7 @@ public void DimAuto_Vertical_TextDirection_Wide_Rune () Height = Dim.Auto () }; - view.SetRelativeLayout (new Size (4, 10)); + view.SetRelativeLayout (new (4, 10)); Assert.Equal (5, text.Length); @@ -714,6 +710,7 @@ string GetContents () Application.End (rs); top.Dispose (); } + [Theory] [AutoInitShutdown] [InlineData (true)] @@ -997,7 +994,6 @@ public void View_Draw_Vertical_Simple_TextAlignments (bool autoSize) top.Dispose (); } - [Fact] [SetupFakeDriver] public void Narrow_Wide_Runes () diff --git a/Tests/UnitTests/View/ViewCommandTests.cs b/Tests/UnitTests/View/ViewCommandTests.cs index 728cc3bff1..a9a8273aee 100644 --- a/Tests/UnitTests/View/ViewCommandTests.cs +++ b/Tests/UnitTests/View/ViewCommandTests.cs @@ -2,137 +2,16 @@ namespace Terminal.Gui.ViewTests; public class ViewCommandTests { - #region OnAccept/Accept tests - - [Fact] - public void Accept_Command_Raises_NoFocus () - { - var view = new ViewEventTester (); - Assert.False (view.HasFocus); - - Assert.False (view.InvokeCommand (Command.Accept)); // there's no superview, so it should return true? - - Assert.Equal (1, view.OnAcceptedCount); - - Assert.Equal (1, view.AcceptedCount); - - Assert.False (view.HasFocus); - } - - [Fact] - public void Accept_Command_Handle_OnAccept_NoEvent () - { - var view = new ViewEventTester (); - Assert.False (view.HasFocus); - - view.HandleOnAccepted = true; - Assert.True (view.InvokeCommand (Command.Accept)); - - Assert.Equal (1, view.OnAcceptedCount); - - Assert.Equal (0, view.AcceptedCount); - } - - [Fact] - public void Accept_Handle_Event_OnAccept_Returns_True () - { - var view = new View (); - var acceptInvoked = false; - - view.Accepting += ViewOnAccept; - - bool? ret = view.InvokeCommand (Command.Accept); - Assert.True (ret); - Assert.True (acceptInvoked); - - return; - - void ViewOnAccept (object sender, CommandEventArgs e) - { - acceptInvoked = true; - e.Cancel = true; - } - } - - [Fact] - public void Accept_Command_Invokes_Accept_Event () - { - var view = new View (); - var accepted = false; - - view.Accepting += ViewOnAccept; - - view.InvokeCommand (Command.Accept); - Assert.True (accepted); - - return; - - void ViewOnAccept (object sender, CommandEventArgs e) { accepted = true; } - } - - // Accept on subview should bubble up to parent - [Fact] - public void Accept_Command_Bubbles_Up_To_SuperView () - { - var view = new ViewEventTester { Id = "view" }; - var subview = new ViewEventTester { Id = "subview" }; - view.Add (subview); - - subview.InvokeCommand (Command.Accept); - Assert.Equal (1, subview.OnAcceptedCount); - Assert.Equal (1, view.OnAcceptedCount); - - subview.HandleOnAccepted = true; - subview.InvokeCommand (Command.Accept); - Assert.Equal (2, subview.OnAcceptedCount); - Assert.Equal (1, view.OnAcceptedCount); - - subview.HandleOnAccepted = false; - subview.HandleAccepted = true; - subview.InvokeCommand (Command.Accept); - Assert.Equal (3, subview.OnAcceptedCount); - Assert.Equal (1, view.OnAcceptedCount); - - // Add a super view to test deeper hierarchy - var superView = new ViewEventTester { Id = "superView" }; - superView.Add (view); - - subview.InvokeCommand (Command.Accept); - Assert.Equal (4, subview.OnAcceptedCount); - Assert.Equal (1, view.OnAcceptedCount); - Assert.Equal (0, superView.OnAcceptedCount); - - subview.HandleAccepted = false; - subview.InvokeCommand (Command.Accept); - Assert.Equal (5, subview.OnAcceptedCount); - Assert.Equal (2, view.OnAcceptedCount); - Assert.Equal (1, superView.OnAcceptedCount); - - view.HandleAccepted = true; - subview.InvokeCommand (Command.Accept); - Assert.Equal (6, subview.OnAcceptedCount); - Assert.Equal (3, view.OnAcceptedCount); - Assert.Equal (1, superView.OnAcceptedCount); - } - - [Fact] - public void MouseClick_Does_Not_Invoke_Accept_Command () - { - var view = new ViewEventTester (); - view.NewMouseEvent (new () { Flags = MouseFlags.Button1Clicked, Position = Point.Empty, View = view }); - - Assert.Equal (0, view.OnAcceptedCount); - } - + // See https://github.com/gui-cs/Terminal.Gui/issues/3913 [Fact] public void Button_IsDefault_Raises_Accepted_Correctly () { - int A_AcceptedCount = 0; - bool A_CancelAccepting = false; + int aAcceptedCount = 0; + bool aCancelAccepting = false; - int B_AcceptedCount = 0; - bool B_CancelAccepting = false; + int bAcceptedCount = 0; + bool bCancelAccepting = false; var w = new Window () { @@ -148,8 +27,8 @@ public void Button_IsDefault_Raises_Accepted_Correctly () }; btnA.Accepting += (s, e) => { - A_AcceptedCount++; - e.Cancel = A_CancelAccepting; + aAcceptedCount++; + e.Cancel = aCancelAccepting; }; var btnB = new Button () @@ -160,12 +39,12 @@ public void Button_IsDefault_Raises_Accepted_Correctly () btnB.Accepting += (s, e) => { - B_AcceptedCount++; - e.Cancel = B_CancelAccepting; + bAcceptedCount++; + e.Cancel = bCancelAccepting; }; w.Add (btnA, btnB); - w.LayoutSubviews (); + w.LayoutSubViews (); Application.Top = w; Application.TopLevels.Push(w); @@ -182,10 +61,10 @@ public void Button_IsDefault_Raises_Accepted_Correctly () }); // Button A should have been accepted because B didn't cancel and A IsDefault - Assert.Equal (1, A_AcceptedCount); - Assert.Equal (1, B_AcceptedCount); + Assert.Equal (1, aAcceptedCount); + Assert.Equal (1, bAcceptedCount); - B_CancelAccepting = true; + bCancelAccepting = true; Application.RaiseMouseEvent ( new MouseEventArgs () { @@ -194,8 +73,8 @@ public void Button_IsDefault_Raises_Accepted_Correctly () }); // Button A (IsDefault) should NOT have been accepted because B canceled - Assert.Equal (1, A_AcceptedCount); - Assert.Equal (2, B_AcceptedCount); + Assert.Equal (1, aAcceptedCount); + Assert.Equal (2, bAcceptedCount); Application.ResetState (true); } @@ -243,7 +122,7 @@ public void Button_CanFocus_False_Raises_Accepted_Correctly () Application.TopLevels.Push (w); Assert.Same (Application.Top, w); - w.LayoutSubviews (); + w.LayoutSubViews (); // Click button just like a driver would var btnFrame = btn.FrameToScreen (); @@ -273,174 +152,4 @@ public void Button_CanFocus_False_Raises_Accepted_Correctly () Application.ResetState (true); } - - #endregion OnAccept/Accept tests - - #region OnSelect/Select tests - - [Theory] - [CombinatorialData] - public void Select_Command_Raises_SetsFocus (bool canFocus) - { - var view = new ViewEventTester - { - CanFocus = canFocus - }; - - Assert.Equal (canFocus, view.CanFocus); - Assert.False (view.HasFocus); - - view.InvokeCommand (Command.Select); - - Assert.Equal (1, view.OnSelectingCount); - - Assert.Equal (1, view.SelectingCount); - - Assert.Equal (canFocus, view.HasFocus); - } - - [Fact] - public void Select_Command_Handle_OnSelecting_NoEvent () - { - var view = new ViewEventTester (); - Assert.False (view.HasFocus); - - view.HandleOnSelecting = true; - Assert.True (view.InvokeCommand (Command.Select)); - - Assert.Equal (1, view.OnSelectingCount); - - Assert.Equal (0, view.SelectingCount); - } - - [Fact] - public void Select_Handle_Event_OnSelecting_Returns_True () - { - var view = new View (); - var SelectingInvoked = false; - - view.Selecting += ViewOnSelect; - - bool? ret = view.InvokeCommand (Command.Select); - Assert.True (ret); - Assert.True (SelectingInvoked); - - return; - - void ViewOnSelect (object sender, CommandEventArgs e) - { - SelectingInvoked = true; - e.Cancel = true; - } - } - - [Fact] - public void Select_Command_Invokes_Selecting_Event () - { - var view = new View (); - var selecting = false; - - view.Selecting += ViewOnSelecting; - - view.InvokeCommand (Command.Select); - Assert.True (selecting); - - return; - - void ViewOnSelecting (object sender, CommandEventArgs e) { selecting = true; } - } - - [Fact] - public void MouseClick_Invokes_Select_Command () - { - var view = new ViewEventTester (); - view.NewMouseEvent (new () { Flags = MouseFlags.Button1Clicked, Position = Point.Empty, View = view }); - - Assert.Equal (1, view.OnSelectingCount); - } - - #endregion OnSelect/Select tests - - #region OnHotKey/HotKey tests - - [Fact] - public void HotKey_Command_SetsFocus () - { - var view = new View (); - - view.CanFocus = true; - Assert.False (view.HasFocus); - view.InvokeCommand (Command.HotKey); - Assert.True (view.HasFocus); - } - - #endregion OnHotKey/HotKey tests - - public class ViewEventTester : View - { - public ViewEventTester () - { - CanFocus = true; - - Accepting += (s, a) => - { - a.Cancel = HandleAccepted; - AcceptedCount++; - }; - - HandlingHotKey += (s, a) => - { - a.Cancel = HandleHandlingHotKey; - HandlingHotKeyCount++; - }; - - Selecting += (s, a) => - { - a.Cancel = HandleSelecting; - SelectingCount++; - }; - } - - public int OnAcceptedCount { get; set; } - public int AcceptedCount { get; set; } - public bool HandleOnAccepted { get; set; } - - /// - protected override bool OnAccepting (CommandEventArgs args) - { - OnAcceptedCount++; - - return HandleOnAccepted; - } - - public bool HandleAccepted { get; set; } - - public int OnHandlingHotKeyCount { get; set; } - public int HandlingHotKeyCount { get; set; } - public bool HandleOnHandlingHotKey { get; set; } - - /// - protected override bool OnHandlingHotKey (CommandEventArgs args) - { - OnHandlingHotKeyCount++; - - return HandleOnHandlingHotKey; - } - - public bool HandleHandlingHotKey { get; set; } - - public int OnSelectingCount { get; set; } - public int SelectingCount { get; set; } - public bool HandleOnSelecting { get; set; } - - /// - protected override bool OnSelecting (CommandEventArgs args) - { - OnSelectingCount++; - - return HandleOnSelecting; - } - - public bool HandleSelecting { get; set; } - } } diff --git a/Tests/UnitTests/View/ViewTests.cs b/Tests/UnitTests/View/ViewTests.cs index f42cc4abd8..5e5a73a6c8 100644 --- a/Tests/UnitTests/View/ViewTests.cs +++ b/Tests/UnitTests/View/ViewTests.cs @@ -1,6 +1,3 @@ -using System.ComponentModel; -using System.Text; -using UnitTests; using UnitTests; using Xunit.Abstractions; @@ -8,11 +5,11 @@ namespace Terminal.Gui.ViewTests; public class ViewTests { - private ITestOutputHelper _output; + private readonly ITestOutputHelper _output; public ViewTests (ITestOutputHelper output) { - output = output; + _output = output; #if DEBUG_IDISPOSABLE View.DebugIDisposable = true; #endif @@ -38,6 +35,7 @@ public void Dispose_Works () public void Disposing_Event_Notify_All_Subscribers_On_The_First_Container () { #if DEBUG_IDISPOSABLE + // Only clear before because need to test after assert View.Instances.Clear (); #endif @@ -46,28 +44,22 @@ public void Disposing_Event_Notify_All_Subscribers_On_The_First_Container () var count = 0; var view = new View { Id = "View" }; - view.Disposing += View_Disposing; + view.Disposing += ViewDisposing; container1.Add (view); Assert.Equal (container1, view.SuperView); - void View_Disposing (object sender, EventArgs e) - { - count++; - Assert.Equal (view, sender); - container1.Remove ((View)sender); - } - - Assert.Single (container1.Subviews); + Assert.Single (container1.SubViews); var container2 = new View { Id = "Container2" }; + // BUGBUG: It's not legit to add a View to two SuperViews container2.Add (view); Assert.Equal (container2, view.SuperView); - Assert.Equal (container1.Subviews.Count, container2.Subviews.Count); + Assert.Equal (container1.SubViews.Count, container2.SubViews.Count); container2.Dispose (); - Assert.Empty (container1.Subviews); - Assert.Empty (container2.Subviews); + Assert.Empty (container1.SubViews); + Assert.Empty (container2.SubViews); Assert.Equal (1, count); Assert.Null (view.SuperView); @@ -76,12 +68,22 @@ void View_Disposing (object sender, EventArgs e) #if DEBUG_IDISPOSABLE Assert.Empty (View.Instances); #endif + + return; + + void ViewDisposing (object sender, EventArgs e) + { + count++; + Assert.Equal (view, sender); + container1.Remove ((View)sender); + } } [Fact] public void Disposing_Event_Notify_All_Subscribers_On_The_Second_Container () { #if DEBUG_IDISPOSABLE + // Only clear before because need to test after assert View.Instances.Clear (); #endif @@ -91,12 +93,13 @@ public void Disposing_Event_Notify_All_Subscribers_On_The_Second_Container () var view = new View { Id = "View" }; container1.Add (view); Assert.Equal (container1, view.SuperView); - Assert.Single (container1.Subviews); + Assert.Single (container1.SubViews); var container2 = new View { Id = "Container2" }; var count = 0; view.Disposing += View_Disposing; + // BUGBUG: It's not legit to add a View to two SuperViews container2.Add (view); Assert.Equal (container2, view.SuperView); @@ -107,11 +110,11 @@ void View_Disposing (object sender, EventArgs e) container2.Remove ((View)sender); } - Assert.Equal (container1.Subviews.Count, container2.Subviews.Count); + Assert.Equal (container1.SubViews.Count, container2.SubViews.Count); container1.Dispose (); - Assert.Empty (container1.Subviews); - Assert.Empty (container2.Subviews); + Assert.Empty (container1.SubViews); + Assert.Empty (container2.SubViews); Assert.Equal (1, count); Assert.Null (view.SuperView); @@ -122,7 +125,6 @@ void View_Disposing (object sender, EventArgs e) #endif } - [Fact] public void Not_Notifying_Dispose () { @@ -136,28 +138,29 @@ public void Not_Notifying_Dispose () container1.Add (view); Assert.Equal (container1, view.SuperView); - Assert.Single (container1.Subviews); + Assert.Single (container1.SubViews); var container2 = new View { Id = "Container2" }; + // BUGBUG: It's not legit to add a View to two SuperViews container2.Add (view); Assert.Equal (container2, view.SuperView); - Assert.Equal (container1.Subviews.Count, container2.Subviews.Count); + Assert.Equal (container1.SubViews.Count, container2.SubViews.Count); container1.Dispose (); - Assert.Empty (container1.Subviews); - Assert.NotEmpty (container2.Subviews); - Assert.Single (container2.Subviews); + Assert.Empty (container1.SubViews); + Assert.NotEmpty (container2.SubViews); + Assert.Single (container2.SubViews); Assert.Null (view.SuperView); // Trying access disposed properties #if DEBUG_IDISPOSABLE - Assert.True (container2.Subviews [0].WasDisposed); + Assert.True (container2.SubViews.ElementAt (0).WasDisposed); #endif - Assert.False (container2.Subviews [0].CanFocus); - Assert.Null (container2.Subviews [0].Margin); - Assert.Null (container2.Subviews [0].Border); - Assert.Null (container2.Subviews [0].Padding); + Assert.False (container2.SubViews.ElementAt (0).CanFocus); + Assert.Null (container2.SubViews.ElementAt (0).Margin); + Assert.Null (container2.SubViews.ElementAt (0).Border); + Assert.Null (container2.SubViews.ElementAt (0).Padding); Assert.Null (view.SuperView); container2.Dispose (); @@ -185,7 +188,7 @@ public void Dispose_View () Assert.Null (view.Border); Assert.Null (view.Padding); } - + [Fact] public void Internal_Tests () { @@ -193,8 +196,6 @@ public void Internal_Tests () var view = new View { Frame = rect }; } - - [Fact] [TestRespondersDisposed] public void New_Initializes () @@ -218,7 +219,7 @@ public void New_Initializes () Assert.Equal (0, r.Y); Assert.False (r.IsCurrentTop); Assert.Empty (r.Id); - Assert.Empty (r.Subviews); + Assert.Empty (r.SubViews); Assert.False (r.WantContinuousButtonPressed); Assert.False (r.WantMousePositionReports); Assert.Null (r.SuperView); @@ -242,7 +243,7 @@ public void New_Initializes () Assert.Equal (0, r.Y); Assert.False (r.IsCurrentTop); Assert.Empty (r.Id); - Assert.Empty (r.Subviews); + Assert.Empty (r.SubViews); Assert.False (r.WantContinuousButtonPressed); Assert.False (r.WantMousePositionReports); Assert.Null (r.SuperView); @@ -266,7 +267,7 @@ public void New_Initializes () Assert.Equal (2, r.Y); Assert.False (r.IsCurrentTop); Assert.Empty (r.Id); - Assert.Empty (r.Subviews); + Assert.Empty (r.SubViews); Assert.False (r.WantContinuousButtonPressed); Assert.False (r.WantMousePositionReports); Assert.Null (r.SuperView); @@ -299,7 +300,7 @@ public void New_Initializes () #else Assert.Equal (string.Empty, r.Id); #endif - Assert.Empty (r.Subviews); + Assert.Empty (r.SubViews); Assert.False (r.WantContinuousButtonPressed); Assert.False (r.WantMousePositionReports); Assert.Null (r.SuperView); @@ -342,7 +343,7 @@ public void Test_Nested_Views_With_Height_Equal_To_One () v.BeginInit (); v.EndInit (); - v.LayoutSubviews (); + v.LayoutSubViews (); v.Draw (); var looksLike = @@ -368,7 +369,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ super.Add (view); super.BeginInit (); super.EndInit (); - super.LayoutSubviews (); + super.LayoutSubViews (); Assert.Equal (1, view.X); Assert.Equal (2, view.Y); @@ -379,7 +380,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.False (view.Viewport.IsEmpty); Assert.Equal (new (0, 0, 3, 4), view.Viewport); - view.LayoutSubviews (); + view.LayoutSubViews (); Assert.Equal (1, view.X); Assert.Equal (2, view.Y); @@ -423,7 +424,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ super.Add (view); super.BeginInit (); super.EndInit (); - super.LayoutSubviews (); + super.LayoutSubViews (); Assert.Equal (1, view.X); Assert.Equal (2, view.Y); Assert.Equal (3, view.Width); @@ -457,15 +458,15 @@ public void Visible_Clear_The_View_Output () ((FakeDriver)Application.Driver!).SetBufferSize (30, 5); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌────────────────────────────┐ │Testing visibility. │ │ │ │ │ └────────────────────────────┘ ", - _output - ); + _output + ); view.Visible = false; @@ -473,22 +474,22 @@ public void Visible_Clear_The_View_Output () Application.RunIteration (ref rs, firstIteration); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌────────────────────────────┐ │ │ │ │ │ │ └────────────────────────────┘ ", - _output - ); + _output + ); Application.End (rs); top.Dispose (); } [Fact] [AutoInitShutdown] - public void Visible_Sets_Also_Sets_Subviews () + public void Visible_Sets_Also_Sets_SubViews () { var button = new Button { Text = "Click Me" }; var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; diff --git a/Tests/UnitTests/ViewTestHelpers.cs b/Tests/UnitTests/ViewTestHelpers.cs deleted file mode 100644 index 63085ef244..0000000000 --- a/Tests/UnitTests/ViewTestHelpers.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System.Reflection; - -namespace UnitTests; - -/// -/// Helpers for View tests. -/// -public class ViewTestHelpers -{ - public static View CreateViewFromType (Type type, ConstructorInfo ctor) - { - View viewType = null; - - if (type.IsGenericType && type.IsTypeDefinition) - { - List gTypes = new (); - - foreach (Type args in type.GetGenericArguments ()) - { - gTypes.Add (typeof (object)); - } - - type = type.MakeGenericType (gTypes.ToArray ()); - - Assert.IsType (type, (View)Activator.CreateInstance (type)); - } - else - { - ParameterInfo [] paramsInfo = ctor.GetParameters (); - Type paramType; - List pTypes = new (); - - if (type.IsGenericType) - { - foreach (Type args in type.GetGenericArguments ()) - { - paramType = args.GetType (); - - if (args.Name == "T") - { - pTypes.Add (typeof (object)); - } - else - { - AddArguments (paramType, pTypes); - } - } - } - - foreach (ParameterInfo p in paramsInfo) - { - paramType = p.ParameterType; - - if (p.HasDefaultValue) - { - pTypes.Add (p.DefaultValue); - } - else - { - AddArguments (paramType, pTypes); - } - } - - if (type.IsGenericType && !type.IsTypeDefinition) - { - viewType = (View)Activator.CreateInstance (type); - Assert.IsType (type, viewType); - } - else - { - viewType = (View)ctor.Invoke (pTypes.ToArray ()); - Assert.IsType (type, viewType); - } - } - - return viewType; - } - - public static List GetAllViewClasses () - { - return typeof (View).Assembly.GetTypes () - .Where ( - myType => myType.IsClass - && !myType.IsAbstract - && myType.IsPublic - && myType.IsSubclassOf (typeof (View)) - ) - .ToList (); - } - - private static void AddArguments (Type paramType, List pTypes) - { - if (paramType == typeof (Rectangle)) - { - pTypes.Add (Rectangle.Empty); - } - else if (paramType == typeof (string)) - { - pTypes.Add (string.Empty); - } - else if (paramType == typeof (int)) - { - pTypes.Add (0); - } - else if (paramType == typeof (bool)) - { - pTypes.Add (true); - } - else if (paramType.Name == "IList") - { - pTypes.Add (new List ()); - } - else if (paramType.Name == "View") - { - var top = new Toplevel (); - var view = new View (); - top.Add (view); - pTypes.Add (view); - } - else if (paramType.Name == "View[]") - { - pTypes.Add (new View [] { }); - } - else if (paramType.Name == "Stream") - { - pTypes.Add (new MemoryStream ()); - } - else if (paramType.Name == "String") - { - pTypes.Add (string.Empty); - } - else if (paramType.Name == "TreeView`1[T]") - { - pTypes.Add (string.Empty); - } - else - { - pTypes.Add (null); - } - } -} diff --git a/Tests/UnitTests/Views/AllViewsTests.cs b/Tests/UnitTests/Views/AllViewsTests.cs index 9d8f30a352..2fb300f87a 100644 --- a/Tests/UnitTests/Views/AllViewsTests.cs +++ b/Tests/UnitTests/Views/AllViewsTests.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Reflection; -using System.Text; -using UnitTests; +using System.Reflection; using UnitTests; using Xunit.Abstractions; @@ -11,16 +8,16 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews { // TODO: Update all these tests to use AllViews like AllViews_Center_Properly does - [Theory] [MemberData (nameof (AllViewTypes))] [SetupFakeDriver] // Required for spinner view that wants to register timeouts public void AllViews_Center_Properly (Type viewType) { // Required for spinner view that wants to register timeouts - Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver)); + Application.MainLoop = new (new FakeMainLoop (Application.Driver)); + + var view = CreateInstanceIfNotGeneric (viewType); - var view = (View)CreateInstanceIfNotGeneric (viewType); // See https://github.com/gui-cs/Terminal.Gui/issues/3156 if (view == null) @@ -47,7 +44,7 @@ public void AllViews_Center_Properly (Type viewType) frame.Add (view); frame.BeginInit (); frame.EndInit (); - frame.LayoutSubviews (); + frame.LayoutSubViews (); // What's the natural width/height? int expectedX = (frame.Frame.Width - view.Frame.Width) / 2; @@ -63,166 +60,6 @@ public void AllViews_Center_Properly (Type viewType) $"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}" ); Application.Shutdown (); - - } - - [Theory] - [MemberData (nameof (AllViewTypes))] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - public void AllViews_Tests_All_Constructors (Type viewType) - { - Assert.True (Test_All_Constructors_Of_Type (viewType)); - } - - - public bool Test_All_Constructors_Of_Type (Type type) - { - foreach (ConstructorInfo ctor in type.GetConstructors ()) - { - View view = ViewTestHelpers.CreateViewFromType (type, ctor); - - if (view != null) - { - Assert.True (type.FullName == view.GetType ().FullName); - } - } - - return true; - } - - //[Fact] - //public void AllViews_HotKey_Works () - //{ - // foreach (var type in GetAllViewClasses ()) { - // _output.WriteLine ($"Testing {type.Name}"); - // var view = GetTypeInitializer (type, type.GetConstructor (Array.Empty ())); - // view.HotKeySpecifier = (Rune)'^'; - // view.Text = "^text"; - // Assert.Equal(Key.T, view.HotKey); - // } - //} - - [Theory] - [MemberData (nameof (AllViewTypes))] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - public void AllViews_Command_Select_Raises_Selecting (Type viewType) - { - // Required for spinner view that wants to register timeouts - Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver)); - - var view = (View)CreateInstanceIfNotGeneric (viewType); - - if (view == null) - { - output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - - return; - } - - if (view is IDesignable designable) - { - designable.EnableForDesign (); - } - - var selectingCount = 0; - view.Selecting += (s, e) => selectingCount++; - - var acceptedCount = 0; - view.Accepting += (s, e) => - { - acceptedCount++; - }; - - - if (view.InvokeCommand(Command.Select) == true) - { - Assert.Equal(1, selectingCount); - Assert.Equal (0, acceptedCount); - } - } - - [Theory] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - [MemberData (nameof (AllViewTypes))] - public void AllViews_Command_Accept_Raises_Accepted (Type viewType) - { - // Required for spinner view that wants to register timeouts - Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver)); - - var view = (View)CreateInstanceIfNotGeneric (viewType); - - if (view == null) - { - output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - - return; - } - - if (view is IDesignable designable) - { - designable.EnableForDesign (); - } - - var selectingCount = 0; - view.Selecting += (s, e) => selectingCount++; - - var acceptedCount = 0; - view.Accepting += (s, e) => - { - acceptedCount++; - }; - - - if (view.InvokeCommand (Command.Accept) == true) - { - Assert.Equal (0, selectingCount); - Assert.Equal (1, acceptedCount); - } } - - [Theory] - [MemberData (nameof (AllViewTypes))] - [SetupFakeDriver] // Required for spinner view that wants to register timeouts - public void AllViews_Command_HotKey_Raises_HandlingHotKey (Type viewType) - { - // Required for spinner view that wants to register timeouts - Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver)); - - var view = (View)CreateInstanceIfNotGeneric (viewType); - - if (view == null) - { - output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - - return; - } - - if (view is IDesignable designable) - { - designable.EnableForDesign (); - } - else - { - view.HotKey = Key.T; - } - - var acceptedCount = 0; - view.Accepting += (s, e) => - { - acceptedCount++; - }; - - var handlingHotKeyCount = 0; - view.HandlingHotKey += (s, e) => - { - handlingHotKeyCount++; - }; - - if (view.InvokeCommand (Command.HotKey) == true) - { - Assert.Equal (1, handlingHotKeyCount); - Assert.Equal (0, acceptedCount); - } - } } diff --git a/Tests/UnitTests/Views/AppendAutocompleteTests.cs b/Tests/UnitTests/Views/AppendAutocompleteTests.cs index 53d63261d5..15b10efa8b 100644 --- a/Tests/UnitTests/Views/AppendAutocompleteTests.cs +++ b/Tests/UnitTests/Views/AppendAutocompleteTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.TextTests; diff --git a/Tests/UnitTests/Views/ButtonTests.cs b/Tests/UnitTests/Views/ButtonTests.cs index 1e2fad2557..c5de4070b8 100644 --- a/Tests/UnitTests/Views/ButtonTests.cs +++ b/Tests/UnitTests/Views/ButtonTests.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; -using UnitTests; using UnitTests; using Xunit.Abstractions; @@ -61,12 +59,12 @@ public void Button_AbsoluteSize_Text (string text, int width, int height, int ex { Text = text, Width = width, - Height = height, + Height = height }; - Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.Frame.Size); - Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.Viewport.Size); - Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.GetContentSize ()); + Assert.Equal (new (expectedWidth, expectedHeight), btn1.Frame.Size); + Assert.Equal (new (expectedWidth, expectedHeight), btn1.Viewport.Size); + Assert.Equal (new (expectedWidth, expectedHeight), btn1.GetContentSize ()); Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.TextFormatter.ConstrainToSize); btn1.Dispose (); @@ -88,8 +86,8 @@ public void Button_AbsoluteSize_DefaultText (int width, int height, int expected btn1.Width = width; btn1.Height = height; - Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.Frame.Size); - Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.Viewport.Size); + Assert.Equal (new (expectedWidth, expectedHeight), btn1.Frame.Size); + Assert.Equal (new (expectedWidth, expectedHeight), btn1.Viewport.Size); Assert.Equal (new Size (expectedWidth, expectedHeight), btn1.TextFormatter.ConstrainToSize); btn1.Dispose (); @@ -190,8 +188,6 @@ public void Constructors_Defaults () btn.Layout (); Assert.Equal (new (10, 1), btn.TextFormatter.ConstrainToSize); - - btn.BeginInit (); btn.EndInit (); Assert.Equal ('_', btn.HotKeySpecifier.Value); @@ -207,6 +203,7 @@ public void Constructors_Defaults () Assert.True (btn.CanFocus); btn.SetRelativeLayout (new (100, 100)); + // 0123456789012345678901234567890123456789 // [* Test *] Assert.Equal ('_', btn.HotKeySpecifier.Value); @@ -273,16 +270,16 @@ public void HotKeyChange_Works () [InlineData (true, 1)] public void Space_Fires_Accept (bool focused, int expected) { - View superView = new View () + var superView = new View { - CanFocus = true, + CanFocus = true }; Button button = new (); button.CanFocus = focused; - int acceptInvoked = 0; + var acceptInvoked = 0; button.Accepting += (s, e) => acceptInvoked++; superView.Add (button); @@ -301,16 +298,16 @@ public void Space_Fires_Accept (bool focused, int expected) [InlineData (true, 1)] public void Enter_Fires_Accept (bool focused, int expected) { - View superView = new View () + var superView = new View { - CanFocus = true, + CanFocus = true }; Button button = new (); button.CanFocus = focused; - int acceptInvoked = 0; + var acceptInvoked = 0; button.Accepting += (s, e) => acceptInvoked++; superView.Add (button); @@ -329,9 +326,9 @@ public void Enter_Fires_Accept (bool focused, int expected) [InlineData (true, 1)] public void HotKey_Fires_Accept (bool focused, int expected) { - View superView = new View () + var superView = new View { - CanFocus = true, + CanFocus = true }; Button button = new () @@ -341,7 +338,7 @@ public void HotKey_Fires_Accept (bool focused, int expected) button.CanFocus = focused; - int acceptInvoked = 0; + var acceptInvoked = 0; button.Accepting += (s, e) => acceptInvoked++; superView.Add (button); @@ -604,7 +601,7 @@ public void WantContinuousButtonPressed_True_ButtonClick_Accepts (MouseFlags pre { var me = new MouseEventArgs (); - var button = new Button () + var button = new Button { Width = 1, Height = 1, @@ -615,25 +612,26 @@ public void WantContinuousButtonPressed_True_ButtonClick_Accepts (MouseFlags pre button.Selecting += (s, e) => selectingCount++; var acceptedCount = 0; + button.Accepting += (s, e) => - { - acceptedCount++; - e.Cancel = true; - }; + { + acceptedCount++; + e.Cancel = true; + }; - me = new MouseEventArgs (); + me = new (); me.Flags = pressed; button.NewMouseEvent (me); Assert.Equal (0, selectingCount); Assert.Equal (0, acceptedCount); - me = new MouseEventArgs (); + me = new (); me.Flags = released; button.NewMouseEvent (me); Assert.Equal (0, selectingCount); Assert.Equal (0, acceptedCount); - me = new MouseEventArgs (); + me = new (); me.Flags = clicked; button.NewMouseEvent (me); Assert.Equal (1, selectingCount); @@ -651,7 +649,7 @@ public void WantContinuousButtonPressed_True_ButtonPressRelease_Does_Not_Raise_S { var me = new MouseEventArgs (); - var button = new Button () + var button = new Button { Width = 1, Height = 1, @@ -661,18 +659,18 @@ public void WantContinuousButtonPressed_True_ButtonPressRelease_Does_Not_Raise_S var acceptedCount = 0; button.Accepting += (s, e) => - { - acceptedCount++; - e.Cancel = true; - }; + { + acceptedCount++; + e.Cancel = true; + }; var selectingCount = 0; button.Selecting += (s, e) => - { - selectingCount++; - e.Cancel = true; - }; + { + selectingCount++; + e.Cancel = true; + }; me.Flags = pressed; button.NewMouseEvent (me); @@ -686,5 +684,4 @@ public void WantContinuousButtonPressed_True_ButtonPressRelease_Does_Not_Raise_S button.Dispose (); } - -} \ No newline at end of file +} diff --git a/Tests/UnitTests/Views/ColorPicker16Tests.cs b/Tests/UnitTests/Views/ColorPicker16Tests.cs index 38d46947f5..53182a950b 100644 --- a/Tests/UnitTests/Views/ColorPicker16Tests.cs +++ b/Tests/UnitTests/Views/ColorPicker16Tests.cs @@ -14,7 +14,7 @@ public void Constructors () colorPicker.BeginInit (); colorPicker.EndInit (); - colorPicker.LayoutSubviews (); + colorPicker.LayoutSubViews (); Assert.Equal (new (0, 0, 32, 4), colorPicker.Frame); } diff --git a/Tests/UnitTests/Views/ColorPickerTests.cs b/Tests/UnitTests/Views/ColorPickerTests.cs index 076e2a8fa0..121696ff1d 100644 --- a/Tests/UnitTests/Views/ColorPickerTests.cs +++ b/Tests/UnitTests/Views/ColorPickerTests.cs @@ -80,7 +80,7 @@ public void ColorPicker_ChangeValueOnUI_UpdatesAllUIElements () Assert.Equal ("#000000", hex.Text); // Change value using text field - TextField rBarTextField = cp.Subviews.OfType ().First (tf => tf.Text == "0"); + TextField rBarTextField = cp.SubViews.OfType ().First (tf => tf.Text == "0"); rBarTextField.SetFocus (); rBarTextField.Text = "128"; @@ -188,7 +188,7 @@ public void ColorPicker_ClickingDifferentBars_ChangesFocus () ScreenPosition = new (0, 1) }); - //cp.Subviews.OfType () + //cp.SubViews.OfType () // .Single () // .OnMouseEvent ( // new () @@ -209,7 +209,7 @@ public void ColorPicker_ClickingDifferentBars_ChangesFocus () ScreenPosition = new (0, 2) }); - //cp.Subviews.OfType () + //cp.SubViews.OfType () // .Single () // .OnMouseEvent ( // new () @@ -232,7 +232,7 @@ public void ColorPicker_Construct_DefaultValue () ColorPicker cp = GetColorPicker (ColorModel.HSV, false); // Should be only a single text field (Hex) because ShowTextFields is false - Assert.Single (cp.Subviews.OfType ()); + Assert.Single (cp.SubViews.OfType ()); cp.Draw (); @@ -308,9 +308,6 @@ public void ColorPicker_DisposesOldViews_OnModelChange () public void ColorPicker_EnterHexFor_ColorName () { ColorPicker cp = GetColorPicker (ColorModel.RGB, true, true); - Application.Navigation = new (); - Application.Top = new (); - Application.Top.Add (cp); cp.Draw (); @@ -367,9 +364,6 @@ public void ColorPicker_EnterHexFor_ColorName () public void ColorPicker_EnterHexFor_ColorName_AcceptVariation () { ColorPicker cp = GetColorPicker (ColorModel.RGB, true, true); - Application.Navigation = new (); - Application.Top = new (); - Application.Top.Add (cp); cp.Draw (); @@ -426,7 +420,7 @@ public void ColorPicker_InvalidHexInput_DoesNotChangeColor () cp.Draw (); // Enter invalid hex value - TextField hexField = cp.Subviews.OfType ().First (tf => tf.Text == "#000000"); + TextField hexField = cp.SubViews.OfType ().First (tf => tf.Text == "#000000"); hexField.SetFocus (); hexField.Text = "#ZZZZZZ"; Assert.True (hexField.HasFocus); @@ -698,7 +692,7 @@ public void ColorPicker_SyncBetweenTextFieldAndBars () cp.Draw (); // Change value using the bar - RBar rBar = cp.Subviews.OfType ().First (); + RBar rBar = cp.SubViews.OfType ().First (); rBar.Value = 128; cp.Draw (); @@ -730,9 +724,6 @@ public void ColorPicker_SyncBetweenTextFieldAndBars () public void ColorPicker_TabCompleteColorName () { ColorPicker cp = GetColorPicker (ColorModel.RGB, true, true); - Application.Navigation = new (); - Application.Top = new (); - Application.Top.Add (cp); cp.Draw (); @@ -838,7 +829,7 @@ private ColorBar GetColorBar (ColorPicker cp, ColorPickerPart toGet) { if (toGet <= ColorPickerPart.Bar3) { - return cp.Subviews.OfType ().ElementAt ((int)toGet); + return cp.SubViews.OfType ().ElementAt ((int)toGet); } throw new NotSupportedException ("ColorPickerPart must be a bar"); @@ -852,10 +843,12 @@ private ColorPicker GetColorPicker (ColorModel colorModel, bool showTextFields, cp.Style.ShowColorName = showName; cp.ApplyStyleChanges (); + Application.Navigation = new (); + Application.Top = new() { Width = 20, Height = 5 }; Application.Top.Add (cp); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); Application.Top.SetFocus (); return cp; @@ -876,20 +869,20 @@ private TextField GetTextField (ColorPicker cp, ColorPickerPart toGet) throw new NotSupportedException ("Corresponding Style option is not enabled"); } - return cp.Subviews.OfType ().ElementAt ((int)toGet); + return cp.SubViews.OfType ().ElementAt ((int)toGet); case ColorPickerPart.ColorName: if (!hasColorNameTextField) { throw new NotSupportedException ("Corresponding Style option is not enabled"); } - return cp.Subviews.OfType ().ElementAt (hasBarValueTextFields ? (int)toGet : (int)toGet - 3); + return cp.SubViews.OfType ().ElementAt (hasBarValueTextFields ? (int)toGet : (int)toGet - 3); case ColorPickerPart.Hex: int offset = hasBarValueTextFields ? 0 : 3; offset += hasColorNameTextField ? 0 : 1; - return cp.Subviews.OfType ().ElementAt ((int)toGet - offset); + return cp.SubViews.OfType ().ElementAt ((int)toGet - offset); default: throw new ArgumentOutOfRangeException (nameof (toGet), toGet, null); } diff --git a/Tests/UnitTests/Views/ComboBoxTests.cs b/Tests/UnitTests/Views/ComboBoxTests.cs index bec3a75781..0e69ac2b3a 100644 --- a/Tests/UnitTests/Views/ComboBoxTests.cs +++ b/Tests/UnitTests/Views/ComboBoxTests.cs @@ -1,6 +1,5 @@ using System.Collections.ObjectModel; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -16,10 +15,10 @@ public void Constructor_With_Source_Initialize_With_The_Passed_SelectedItem () }; cb.BeginInit (); cb.EndInit (); - cb.LayoutSubviews (); + cb.LayoutSubViews (); Assert.Equal ("Two", cb.Text); Assert.NotNull (cb.Source); - Assert.Equal (new Rectangle (0, 0, 0, 2), cb.Frame); + Assert.Equal (new (0, 0, 0, 2), cb.Frame); Assert.Equal (1, cb.SelectedItem); } @@ -30,22 +29,22 @@ public void Constructors_Defaults () var cb = new ComboBox (); cb.BeginInit (); cb.EndInit (); - cb.LayoutSubviews (); + cb.LayoutSubViews (); Assert.Equal (string.Empty, cb.Text); Assert.Null (cb.Source); - Assert.Equal (new Rectangle (0, 0, 0, 2), cb.Frame); + Assert.Equal (new (0, 0, 0, 2), cb.Frame); Assert.Equal (-1, cb.SelectedItem); - cb = new ComboBox { Text = "Test" }; + cb = new() { Text = "Test" }; cb.BeginInit (); cb.EndInit (); - cb.LayoutSubviews (); + cb.LayoutSubViews (); Assert.Equal ("Test", cb.Text); Assert.Null (cb.Source); - Assert.Equal (new Rectangle (0, 0, 0, 2), cb.Frame); + Assert.Equal (new (0, 0, 0, 2), cb.Frame); Assert.Equal (-1, cb.SelectedItem); - cb = new ComboBox + cb = new() { X = 1, Y = 2, @@ -55,19 +54,19 @@ public void Constructors_Defaults () }; cb.BeginInit (); cb.EndInit (); - cb.LayoutSubviews (); + cb.LayoutSubViews (); Assert.Equal (string.Empty, cb.Text); Assert.NotNull (cb.Source); - Assert.Equal (new Rectangle (1, 2, 10, 20), cb.Frame); + Assert.Equal (new (1, 2, 10, 20), cb.Frame); Assert.Equal (-1, cb.SelectedItem); - cb = new ComboBox { Source = new ListWrapper (["One", "Two", "Three"]) }; + cb = new() { Source = new ListWrapper (["One", "Two", "Three"]) }; cb.BeginInit (); cb.EndInit (); - cb.LayoutSubviews (); + cb.LayoutSubViews (); Assert.Equal (string.Empty, cb.Text); Assert.NotNull (cb.Source); - Assert.Equal (new Rectangle (0, 0, 0, 2), cb.Frame); + Assert.Equal (new (0, 0, 0, 2), cb.Frame); Assert.Equal (-1, cb.SelectedItem); } @@ -84,7 +83,7 @@ public void EnsureKeyEventsDoNotCauseExceptions () foreach (KeyCode key in (KeyCode [])Enum.GetValues (typeof (KeyCode))) { - Assert.Null (Record.Exception (() => comboBox.NewKeyDownEvent (new Key (key)))); + Assert.Null (Record.Exception (() => comboBox.NewKeyDownEvent (new (key)))); } } @@ -139,19 +138,19 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_Cu Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewMouseEvent (new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed })); + Assert.True (cb.NewMouseEvent (new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed })); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -162,7 +161,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_Cu Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -195,15 +194,15 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); @@ -233,21 +232,21 @@ public void Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -258,7 +257,7 @@ public void Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -291,8 +290,8 @@ public void HideDropdownListOnClick_Gets_Sets () Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -302,10 +301,10 @@ public void HideDropdownListOnClick_Gets_Sets () cb.Layout (); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -313,10 +312,10 @@ cb.Subviews [1] Assert.Equal ("Two", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -326,10 +325,10 @@ cb.Subviews [1] cb.HideDropdownListOnClick = true; Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("Three", selected); Assert.False (cb.IsShow); @@ -338,15 +337,15 @@ cb.Subviews [1] Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("Three", selected); Assert.False (cb.IsShow); @@ -355,8 +354,8 @@ cb.Subviews [1] Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); @@ -364,10 +363,10 @@ cb.Subviews [1] Assert.Equal ("Three", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("One", selected); Assert.False (cb.IsShow); @@ -395,15 +394,15 @@ public void HideDropdownListOnClick_True_Colapse_On_Click_Outside_Frame () Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -411,10 +410,10 @@ cb.Subviews [1] Assert.Equal ("", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (-1, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (-1, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -424,10 +423,10 @@ cb.Subviews [1] Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -435,10 +434,10 @@ cb.Subviews [1] Assert.Equal ("", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, -1), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, -1), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -448,10 +447,10 @@ cb.Subviews [1] Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -459,10 +458,10 @@ cb.Subviews [1] Assert.Equal ("", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Frame.Width, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (cb.Frame.Width, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -472,10 +471,10 @@ cb.Subviews [1] Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -483,10 +482,10 @@ cb.Subviews [1] Assert.Equal ("", cb.Text); Assert.True ( - cb.Subviews [1] + cb.SubViews.ElementAt (1) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, cb.Frame.Height), Flags = MouseFlags.Button1Clicked } - ) + new() { Position = new (0, cb.Frame.Height), Flags = MouseFlags.Button1Clicked } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -505,7 +504,7 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () cb.OpenSelectedItem += (s, e) => selected = e.Value.ToString (); var top = new Toplevel (); - View otherView = new View () { CanFocus = true }; + var otherView = new View { CanFocus = true }; top.Add (otherView, cb); Application.Begin (top); @@ -519,8 +518,8 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); @@ -532,38 +531,38 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () cb.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ▼ One Two Three ", - output - ); + output + ); Attribute [] attributes = { // 0 - cb.Subviews [0].ColorScheme.Focus, + cb.SubViews.ElementAt (0).ColorScheme.Focus, // 1 - cb.Subviews [1].ColorScheme.HotFocus, + cb.SubViews.ElementAt (1).ColorScheme.HotFocus, // 2 - cb.Subviews [1].GetNormalColor () + cb.SubViews.ElementAt (1).GetNormalColor () }; DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 222222 222222 222222", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -572,17 +571,17 @@ cb.Subviews [1].GetNormalColor () cb.Draw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 222222 000002 222222", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -591,17 +590,17 @@ cb.Subviews [1].GetNormalColor () cb.Draw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 222222 222222 000002", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.Enter)); Assert.Equal ("Three", selected); Assert.False (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -616,17 +615,17 @@ cb.Subviews [1].GetNormalColor () cb.Draw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 222222 222222 000002", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorUp)); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -635,17 +634,17 @@ cb.Subviews [1].GetNormalColor () cb.Draw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 222222 000002 111112", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorUp)); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -654,15 +653,15 @@ cb.Subviews [1].GetNormalColor () cb.Draw (); DriverAssert.AssertDriverAttributesAre ( - @" + @" 000000 000002 222222 111112", - output, - Application.Driver, - attributes - ); + output, + Application.Driver, + attributes + ); Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.Equal ("Three", selected); @@ -691,20 +690,20 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -713,20 +712,20 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorUp)); Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -754,21 +753,21 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_Cur Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -779,7 +778,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_Cur Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -812,15 +811,15 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.NewMouseEvent ( - new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } - ) + new() { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + ) ); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); Assert.True (Application.RaiseKeyDownEvent (Key.F4)); Assert.Equal ("", selected); Assert.False (cb.IsShow); @@ -839,7 +838,7 @@ public void KeyBindings_Command () top.Add (cb); - var otherView = new View () { CanFocus = true }; + var otherView = new View { CanFocus = true }; top.Add (otherView); Application.Begin (top); @@ -917,13 +916,14 @@ public void KeyBindings_Command () Assert.Equal ("One", cb.Text); cb.Draw (); + DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" One ▼ One ", - output - ); + output + ); Assert.True (Application.RaiseKeyDownEvent (Key.PageDown)); Assert.True (cb.IsShow); @@ -932,13 +932,14 @@ public void KeyBindings_Command () View.SetClipToScreen (); cb.Draw (); + DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Two ▼ Two ", - output - ); + output + ); Assert.True (Application.RaiseKeyDownEvent (Key.PageDown)); Assert.True (cb.IsShow); @@ -947,13 +948,14 @@ public void KeyBindings_Command () View.SetClipToScreen (); cb.Draw (); + DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Three ▼ Three ", - output - ); + output + ); Assert.True (Application.RaiseKeyDownEvent (Key.PageUp)); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -1056,6 +1058,6 @@ public void Source_Equal_Null_Or_Count_Equal_Zero_Sets_SelectedItem_Equal_To_Min Assert.Equal ("", cb.Text); Application.Top.Dispose (); - Application.ResetState (ignoreDisposed: true); + Application.ResetState (true); } } diff --git a/Tests/UnitTests/Views/ContextMenuTests.cs b/Tests/UnitTests/Views/ContextMenuTests.cs index ec555edacb..c600fb30a0 100644 --- a/Tests/UnitTests/Views/ContextMenuTests.cs +++ b/Tests/UnitTests/Views/ContextMenuTests.cs @@ -1,6 +1,4 @@ -using System.Globalization; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -533,9 +531,9 @@ public void Menus_And_SubMenus_Always_Try_To_Be_On_Screen () ); Assert.True ( - top.Subviews [0] + top.SubViews.ElementAt (0) .NewMouseEvent ( - new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (0) } ) ); Application.RunIteration (ref rs); @@ -581,9 +579,9 @@ top.Subviews [0] ); Assert.True ( - top.Subviews [0] + top.SubViews.ElementAt (0) .NewMouseEvent ( - new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (0) } ) ); Application.RunIteration (ref rs); @@ -628,9 +626,9 @@ top.Subviews [0] ); Assert.True ( - top.Subviews [0] + top.SubViews.ElementAt (0) .NewMouseEvent ( - new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (0) } ) ); Application.RunIteration (ref rs); @@ -672,9 +670,9 @@ top.Subviews [0] ); Assert.True ( - top.Subviews [0] + top.SubViews.ElementAt (0) .NewMouseEvent ( - new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (0) } ) ); Application.RunIteration (ref rs); @@ -716,9 +714,9 @@ top.Subviews [0] ); Assert.True ( - top.Subviews [0] + top.SubViews.ElementAt (0) .NewMouseEvent ( - new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (0) } ) ); Application.RunIteration (ref rs); @@ -1225,7 +1223,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () Toplevel top = new (); RunState rs = Application.Begin (top); cm.Show (menuItems); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top!.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top!.SubViews.ElementAt (0).Frame); Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( @@ -1243,8 +1241,8 @@ public void UseSubMenusSingleFrame_True_By_Mouse () var firstIteration = false; Application.RunIteration (ref rs, firstIteration); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); - Assert.Equal (new Rectangle (5, 11, 15, 6), Application.Top.Subviews [1].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); + Assert.Equal (new Rectangle (5, 11, 15, 6), Application.Top.SubViews.ElementAt (1).Frame); DriverAssert.AssertDriverContentsWithFrameAre ( @" @@ -1261,7 +1259,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () firstIteration = false; Application.RunIteration (ref rs, firstIteration); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); DriverAssert.AssertDriverContentsWithFrameAre ( @" @@ -1318,7 +1316,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () RunState rs = Application.Begin (top); cm.Show (menuItems); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( @@ -1335,7 +1333,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () var firstIteration = false; Application.RunIteration (ref rs, firstIteration); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); DriverAssert.AssertDriverContentsWithFrameAre ( @" @@ -1352,7 +1350,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () firstIteration = false; Application.RunIteration (ref rs, firstIteration); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); DriverAssert.AssertDriverContentsWithFrameAre ( @" @@ -1370,7 +1368,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () firstIteration = false; Application.RunIteration (ref rs, firstIteration); - Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame); + Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.SubViews.ElementAt (0).Frame); DriverAssert.AssertDriverContentsWithFrameAre ( @" @@ -1399,14 +1397,14 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Assert.True (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (4, win.Subviews.Count); // TF & TV add autocomplete popup's to their superviews. + Assert.Equal (4, win.SubViews.Count); // TF & TV add autocomplete popup's to their superviews. Assert.Empty (Application._cachedViewsUnderMouse); // Right click on tf2 to open context menu Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button3Clicked }); Assert.False (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (5, win.Subviews.Count); + Assert.Equal (5, win.SubViews.Count); Assert.True (tf2.ContextMenu.MenuBar.IsMenuOpen); Assert.True (win.Focused is Menu); Assert.True (Application.MouseGrabView is MenuBar); @@ -1416,7 +1414,7 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Clicked }); Assert.True (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (4, win.Subviews.Count); + Assert.Equal (4, win.SubViews.Count); // The last context menu bar opened is always preserved Assert.NotNull (tf2.ContextMenu.MenuBar); @@ -1428,7 +1426,7 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked }); Assert.False (tf1.HasFocus); Assert.True (tf2.HasFocus); - Assert.Equal (4, win.Subviews.Count); + Assert.Equal (4, win.SubViews.Count); // The last context menu bar opened is always preserved Assert.NotNull (tf2.ContextMenu.MenuBar); @@ -1712,8 +1710,8 @@ public void HotKeys_Removed_On_Close_ContextMenu () Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _)); Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.WithAlt, out _)); Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.NoShift, out _)); - Assert.Single (Application.Top!.Subviews); - View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); + Assert.Single (Application.Top!.SubViews); + View [] menus = Application.Top!.SubViews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); Assert.True (menus [0].HotKeyBindings.TryGet (Key.N.WithAlt, out _)); Assert.True (menus [0].HotKeyBindings.TryGet (Key.N.NoShift, out _)); Assert.True (menus [0].HotKeyBindings.TryGet (Key.R.WithAlt, out _)); @@ -1801,14 +1799,14 @@ public void HotKeys_With_ContextMenu_And_MenuBar () Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.WithAlt, out _)); Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _)); Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _)); - View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray (); + View [] menus = Application.Top!.SubViews.Where (v => v is Menu m && m.Host == menuBar).ToArray (); Assert.Empty (menus); Assert.Null (cm.MenuBar); Assert.True (Application.RaiseKeyDownEvent (Key.F.WithAlt)); Assert.True (menuBar.IsMenuOpen); - Assert.Equal (2, Application.Top!.Subviews.Count); - menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray (); + Assert.Equal (2, Application.Top!.SubViews.Count); + menus = Application.Top!.SubViews.Where (v => v is Menu m && m.Host == menuBar).ToArray (); Assert.True (menus [0].HotKeyBindings.TryGet (Key.N.WithAlt, out _)); Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt)); Assert.False (menuBar.IsMenuOpen); @@ -1837,8 +1835,8 @@ public void HotKeys_With_ContextMenu_And_MenuBar () Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.E.NoShift, out _)); Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _)); Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _)); - Assert.Equal (3, Application.Top!.Subviews.Count); - menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); + Assert.Equal (3, Application.Top!.SubViews.Count); + menus = Application.Top!.SubViews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.WithAlt, out _)); Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.NoShift, out _)); Assert.True (menus [1].HotKeyBindings.TryGet (Key.R.WithAlt, out _)); @@ -1852,8 +1850,8 @@ public void HotKeys_With_ContextMenu_And_MenuBar () cm.Show (menuItems); Assert.True (cm.MenuBar.IsMenuOpen); - Assert.Equal (3, Application.Top!.Subviews.Count); - menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); + Assert.Equal (3, Application.Top!.SubViews.Count); + menus = Application.Top!.SubViews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray (); Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.WithAlt, out _)); Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.NoShift, out _)); Assert.False (menus [0].HotKeyBindings.TryGet (Key.R.WithAlt, out _)); @@ -1868,7 +1866,7 @@ public void HotKeys_With_ContextMenu_And_MenuBar () Application.MainLoop!.RunIteration (); Assert.True (renameFile); - Assert.Single (Application.Top!.Subviews); + Assert.Single (Application.Top!.SubViews); Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.WithAlt, out _)); Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.NoShift, out _)); Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _)); diff --git a/Tests/UnitTests/Views/DatePickerTests.cs b/Tests/UnitTests/Views/DatePickerTests.cs index 85096ec4dc..789d960ce0 100644 --- a/Tests/UnitTests/Views/DatePickerTests.cs +++ b/Tests/UnitTests/Views/DatePickerTests.cs @@ -72,22 +72,22 @@ public void DatePicker_ShouldNot_SetDateOutOfRange_UsingNextMonthButton () top.Add (datePicker); Application.Begin (top); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_dateField"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_dateField"), datePicker.Focused); // Set focus to next month button datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_calendar"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_calendar"), datePicker.Focused); datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_nextMonthButton"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_nextMonthButton"), datePicker.Focused); // Change month to December Assert.False (Application.RaiseKeyDownEvent (Key.Enter)); Assert.Equal (12, datePicker.Date.Month); // Next month button is disabled, so focus advanced to edit field - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); top.Dispose (); } @@ -104,19 +104,19 @@ public void DatePicker_ShouldNot_SetDateOutOfRange_UsingPreviousMonthButton () top.Add (datePicker); Application.Begin (top); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_dateField"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_dateField"), datePicker.Focused); datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_calendar"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_calendar"), datePicker.Focused); datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_previousMonthButton"), datePicker.Focused); // Change month to January Assert.False (datePicker.NewKeyDownEvent (Key.Enter)); Assert.Equal (1, datePicker.Date.Month); // Next prev button is disabled, so focus advanced to edit button - Assert.Equal (datePicker.Subviews.First (v => v.Id == "_calendar"), datePicker.Focused); + Assert.Equal (datePicker.SubViews.First (v => v.Id == "_calendar"), datePicker.Focused); top.Dispose (); } diff --git a/Tests/UnitTests/Views/FrameViewTests.cs b/Tests/UnitTests/Views/FrameViewTests.cs index 0d559919e7..c2dd13a0d0 100644 --- a/Tests/UnitTests/Views/FrameViewTests.cs +++ b/Tests/UnitTests/Views/FrameViewTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; diff --git a/Tests/UnitTests/Views/GraphViewTests.cs b/Tests/UnitTests/Views/GraphViewTests.cs index ef5230f664..7e53c68315 100644 --- a/Tests/UnitTests/Views/GraphViewTests.cs +++ b/Tests/UnitTests/Views/GraphViewTests.cs @@ -1,7 +1,5 @@ using System.Text; using UnitTests; -using Terminal.Gui.ViewMouseTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -466,7 +464,7 @@ public void Series_GetsPassedCorrectViewport_AllAtOnce () ); gv.Series.Add (series); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.Equal (new RectangleF (0, 0, 50, 30), fullGraphBounds); Assert.Equal (new Rectangle (0, 0, 50, 30), graphScreenBounds); @@ -479,7 +477,7 @@ public void Series_GetsPassedCorrectViewport_AllAtOnce () // Even with a margin the graph should be drawn from // the origin, we just get less visible width/height - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); Assert.Equal (new RectangleF (0, 0, 45, 28), fullGraphBounds); @@ -523,7 +521,7 @@ public void Series_GetsPassedCorrectViewport_AllAtOnce_LargeCellSize () gv.Series.Add (series); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); // Since each cell of the console is 2x5 of graph space the graph @@ -538,7 +536,7 @@ public void Series_GetsPassedCorrectViewport_AllAtOnce_LargeCellSize () // Even with a margin the graph should be drawn from // the origin, we just get less visible width/height - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); Assert.Equal (new RectangleF (0, 0, 90, 140), fullGraphBounds); @@ -668,7 +666,7 @@ public void TestRendering_MultibarSeries () gv.AxisX = fakeXAxis = new FakeHAxis { Increment = 0 }; gv.AxisY = new FakeVAxis { Increment = 0 }; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); // Since bar series has no bars yet no labels should be displayed @@ -676,7 +674,7 @@ public void TestRendering_MultibarSeries () multibarSeries.AddBars ("hey", (Rune)'M', 0.5001f, 0.5001f); fakeXAxis.LabelPoints.Clear (); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); @@ -685,7 +683,7 @@ public void TestRendering_MultibarSeries () multibarSeries.AddBars ("there", (Rune)'M', 0.24999f, 0.74999f); multibarSeries.AddBars ("bob", (Rune)'M', 1, 2); fakeXAxis.LabelPoints.Clear (); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); View.SetClipToScreen (); gv.Draw (); @@ -945,7 +943,7 @@ private GraphView GetGraph (out FakeHAxis axisX, out FakeVAxis axisY) public void TestHAxisLocation_NoMargin () { GraphView gv = GetGraph (out FakeHAxis axis); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (-1, 29), axis.DrawAxisLinePoints); @@ -969,7 +967,7 @@ public void TestHAxisLocation_MarginBottom () GraphView gv = GetGraph (out FakeHAxis axis); gv.MarginBottom = 10; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (-1, 19), axis.DrawAxisLinePoints); @@ -993,7 +991,7 @@ public void TestHAxisLocation_MarginLeft () GraphView gv = GetGraph (out FakeHAxis axis); gv.MarginLeft = 5; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (4, 29), axis.DrawAxisLinePoints); @@ -1022,7 +1020,7 @@ public void TestVAxisLocation_NoMargin () { GraphView gv = GetGraph (out FakeVAxis axis); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints); @@ -1046,7 +1044,7 @@ public void TestVAxisLocation_MarginBottom () GraphView gv = GetGraph (out FakeVAxis axis); gv.MarginBottom = 10; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints); @@ -1071,7 +1069,7 @@ public void TestVAxisLocation_MarginLeft () GraphView gv = GetGraph (out FakeVAxis axis); gv.MarginLeft = 5; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); Assert.DoesNotContain (new Point (5, -1), axis.DrawAxisLinePoints); @@ -1114,7 +1112,7 @@ public void TestTextAnnotation_EmptyText (string whitespace) var points = new ScatterSeries (); points.Points.Add (new PointF (7, 2)); gv.Series.Add (points); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1140,7 +1138,7 @@ public void TestTextAnnotation_GraphUnits () new TextAnnotation { Text = "hey!", GraphPosition = new PointF (2, 2) } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1189,7 +1187,7 @@ public void TestTextAnnotation_LongText () } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); @@ -1223,7 +1221,7 @@ public void TestTextAnnotation_Offscreen () } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); // Text is off the screen (graph x axis runs to 8 not 9) @@ -1249,7 +1247,7 @@ public void TestTextAnnotation_ScreenUnits () gv.Annotations.Add ( new TextAnnotation { Text = "hey!", ScreenPosition = new Point (3, 1) } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); View.SetClipToScreen (); gv.Draw (); @@ -1403,7 +1401,7 @@ public void MarginBottom_BiggerThanHeight_ExpectBlankGraph () new ScatterSeries { Points = { new PointF (1, 1), new PointF (5, 0) } } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1428,7 +1426,7 @@ public void MarginLeft_BiggerThanWidth_ExpectBlankGraph () new ScatterSeries { Points = { new PointF (1, 1), new PointF (5, 0) } } ); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1458,7 +1456,7 @@ public void PathAnnotation_Box () path.Points.Add (new PointF (1, 1)); gv.Annotations.Add (path); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1491,7 +1489,7 @@ public void PathAnnotation_Diamond () gv.Annotations.Add (path); - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.Draw (); var expected = @@ -1586,7 +1584,7 @@ public void XAxisLabels_With_MarginLeft () gv.MarginLeft = 3; gv.MarginBottom = 1; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); @@ -1625,7 +1623,7 @@ public void YAxisLabels_With_MarginBottom () gv.MarginBottom = 3; gv.MarginLeft = 1; - gv.LayoutSubviews (); + gv.LayoutSubViews (); gv.SetNeedsDraw (); gv.Draw (); diff --git a/Tests/UnitTests/Views/HexViewTests.cs b/Tests/UnitTests/Views/HexViewTests.cs index 4911570c43..82191e8292 100644 --- a/Tests/UnitTests/Views/HexViewTests.cs +++ b/Tests/UnitTests/Views/HexViewTests.cs @@ -38,7 +38,7 @@ public void AllowEdits_Edits_ApplyEdits () Application.Top.SetFocus (); // Needed because HexView relies on LayoutComplete to calc sizes - hv.LayoutSubviews (); + hv.LayoutSubViews (); Assert.True (Application.RaiseKeyDownEvent (Key.Tab)); // Move to left side @@ -94,7 +94,7 @@ public void ApplyEdits_With_Argument () Application.Top.SetFocus (); // Needed because HexView relies on LayoutComplete to calc sizes - hv.LayoutSubviews (); + hv.LayoutSubViews (); var readBuffer = new byte [hv.Source!.Length]; hv.Source.Position = 0; @@ -151,7 +151,7 @@ public void Position_Encoding_Default () Application.Top = new Toplevel (); Application.Top.Add (hv); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); Assert.Equal (63, hv.Source!.Length); Assert.Equal (20, hv.BytesPerLine); @@ -189,7 +189,7 @@ public void Position_Encoding_Unicode () Application.Top = new Toplevel (); Application.Top.Add (hv); - hv.LayoutSubviews (); + hv.LayoutSubViews (); Assert.Equal (126, hv.Source!.Length); Assert.Equal (20, hv.BytesPerLine); @@ -223,7 +223,7 @@ public void DiscardEdits_Method () var hv = new HexView (LoadStream (null, out _, true)) { Width = 20, Height = 20 }; // Needed because HexView relies on LayoutComplete to calc sizes - hv.LayoutSubviews (); + hv.LayoutSubViews (); Assert.True (hv.NewKeyDownEvent (Key.D4)); Assert.True (hv.NewKeyDownEvent (Key.D1)); @@ -242,7 +242,7 @@ public void Edited_Event () var hv = new HexView (LoadStream (null, out _, true)) { Width = 20, Height = 20 }; // Needed because HexView relies on LayoutComplete to calc sizes - hv.LayoutSubviews (); + hv.LayoutSubViews (); KeyValuePair keyValuePair = default; hv.Edited += (s, e) => keyValuePair = new (e.Address, e.NewValue); @@ -270,7 +270,7 @@ public void KeyBindings_Test_Movement_LeftSide () var hv = new HexView (LoadStream (null, out _)) { Width = 20, Height = 10 }; Application.Top.Add (hv); - hv.LayoutSubviews (); + hv.LayoutSubViews (); Assert.Equal (MEM_STRING_LENGTH, hv.Source!.Length); Assert.Equal (0, hv.Address); @@ -325,7 +325,7 @@ public void PositionChanged_Event () Application.Top = new Toplevel (); Application.Top.Add (hv); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); HexViewEventArgs hexViewEventArgs = null!; hv.PositionChanged += (s, e) => hexViewEventArgs = e; diff --git a/Tests/UnitTests/Views/LabelTests.cs b/Tests/UnitTests/Views/LabelTests.cs index 03d8369eaf..3d8ecd2eb6 100644 --- a/Tests/UnitTests/Views/LabelTests.cs +++ b/Tests/UnitTests/Views/LabelTests.cs @@ -1,7 +1,4 @@ -using System.ComponentModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -35,45 +32,45 @@ public void Title_Mirrors_Text () [Theory] [CombinatorialData] - public void HotKey_Command_SetsFocus_OnNextSubview (bool hasHotKey) + public void HotKey_Command_SetsFocus_OnNextSubView (bool hasHotKey) { var superView = new View { CanFocus = true }; var label = new Label (); label.HotKey = hasHotKey ? Key.A.WithAlt : Key.Empty; - var nextSubview = new View { CanFocus = true }; - superView.Add (label, nextSubview); + var nextSubView = new View { CanFocus = true }; + superView.Add (label, nextSubView); superView.BeginInit (); superView.EndInit (); Assert.False (label.HasFocus); - Assert.False (nextSubview.HasFocus); + Assert.False (nextSubView.HasFocus); label.InvokeCommand (Command.HotKey); Assert.False (label.HasFocus); - Assert.Equal (hasHotKey, nextSubview.HasFocus); + Assert.Equal (hasHotKey, nextSubView.HasFocus); } [Theory] [CombinatorialData] - public void MouseClick_SetsFocus_OnNextSubview (bool hasHotKey) + public void MouseClick_SetsFocus_OnNextSubView (bool hasHotKey) { var superView = new View { CanFocus = true, Height = 1, Width = 15 }; var focusedView = new View { CanFocus = true, Width = 1, Height = 1 }; var label = new Label { X = 2 }; label.HotKey = hasHotKey ? Key.X.WithAlt : Key.Empty; - var nextSubview = new View { CanFocus = true, X = 4, Width = 4, Height = 1 }; - superView.Add (focusedView, label, nextSubview); + var nextSubView = new View { CanFocus = true, X = 4, Width = 4, Height = 1 }; + superView.Add (focusedView, label, nextSubView); superView.BeginInit (); superView.EndInit (); Assert.False (focusedView.HasFocus); Assert.False (label.HasFocus); - Assert.False (nextSubview.HasFocus); + Assert.False (nextSubView.HasFocus); label.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }); Assert.False (label.HasFocus); - Assert.Equal (hasHotKey, nextSubview.HasFocus); + Assert.Equal (hasHotKey, nextSubView.HasFocus); } [Fact] @@ -212,12 +209,12 @@ public void Label_Draw_Fill_Remaining () tf2.Draw (new (new (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This label needs to be cleared before rewritten. This TextFormatter (tf1) without fill will not be cleared on rewritten. This TextFormatter (tf2) with fill will be cleared on rewritten. ", - output - ); + output + ); Assert.False (label.NeedsDraw); Assert.False (label.NeedsLayout); @@ -225,6 +222,7 @@ This TextFormatter (tf2) with fill will be cleared on rewritten. ", label.Text = "This label is rewritten."; Assert.True (label.NeedsDraw); Assert.True (label.NeedsLayout); + //Assert.False (label.SubViewNeedsDraw); label.Draw (); @@ -235,12 +233,12 @@ This TextFormatter (tf2) with fill will be cleared on rewritten. ", tf2.Draw (new (new (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This label is rewritten. This TextFormatter (tf1) is rewritten.will not be cleared on rewritten. This TextFormatter (tf2) is rewritten. ", - output - ); + output + ); top.Dispose (); } @@ -461,12 +459,12 @@ public void Full_Border () label.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌┤Te├┐ │Test│ └────┘", - output - ); + output + ); label.Dispose (); } @@ -487,11 +485,11 @@ public void With_Top_Margin_Without_Top_Border () Application.Begin (top); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" │Test│ └────┘", - output - ); + output + ); top.Dispose (); } @@ -510,16 +508,16 @@ public void Without_Top_Border () Application.Begin (top); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" │Test│ └────┘", - output - ); + output + ); top.Dispose (); } // These tests were formally in AutoSizetrue.cs. They are (poor) Label tests. - private readonly string [] expecteds = new string [21] + private readonly string [] _expecteds = new string [21] { @" ┌────────────────────┐ @@ -838,8 +836,6 @@ public void Without_Top_Border () └────────────────────┘" }; - private static readonly Size _size1x1 = new (1, 1); - // TODO: This is a Label test. Move to label tests if there's not already a test for this. [Fact] [AutoInitShutdown] @@ -984,7 +980,7 @@ public void Dim_Subtract_Operator_With_Text () if (k.KeyCode == KeyCode.Enter) { ((FakeDriver)Application.Driver!).SetBufferSize (22, count + 4); - Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expecteds [count], output); + Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (_expecteds [count], output); Assert.Equal (new (0, 0, 22, count + 4), pos); if (count > 0) @@ -1061,7 +1057,7 @@ public void Label_Height_Zero_Stays_Zero () win.Add (label); win.BeginInit (); win.EndInit (); - win.LayoutSubviews (); + win.LayoutSubViews (); win.Draw (); Assert.Equal (5, text.Length); @@ -1084,7 +1080,7 @@ public void Label_Height_Zero_Stays_Zero () text = "0123456789"; Assert.Equal (10, text.Length); label.Width = Dim.Fill () - text.Length; - win.LayoutSubviews (); + win.LayoutSubViews (); win.ClearViewport (); win.Draw (); @@ -1135,7 +1131,7 @@ public void Dim_Add_Operator_With_Text () if (k.KeyCode == KeyCode.Enter) { ((FakeDriver)Application.Driver!).SetBufferSize (22, count + 4); - Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expecteds [count], output); + Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (_expecteds [count], output); Assert.Equal (new (0, 0, 22, count + 4), pos); if (count < 20) @@ -1321,14 +1317,13 @@ public void Label_ResizeView_With_Dim_Absolute () label.Text = "New text"; super.Add (label); - super.LayoutSubviews (); + super.LayoutSubViews (); Rectangle expectedLabelBounds = new (0, 0, 8, 1); Assert.Equal (expectedLabelBounds, label.Viewport); super.Dispose (); } - [Fact] public void CanFocus_False_HotKey_SetsFocus_Next () { @@ -1337,10 +1332,12 @@ public void CanFocus_False_HotKey_SetsFocus_Next () Text = "otherView", CanFocus = true }; + Label label = new () { Text = "_label" }; + View nextView = new () { Text = "nextView", @@ -1362,7 +1359,6 @@ public void CanFocus_False_HotKey_SetsFocus_Next () Application.ResetState (); } - [Fact] public void CanFocus_False_MouseClick_SetsFocus_Next () { @@ -1393,6 +1389,7 @@ public void CanFocus_True_HotKey_SetsFocus () Text = "_label", CanFocus = true }; + View view = new () { Text = "view", @@ -1417,11 +1414,11 @@ public void CanFocus_True_HotKey_SetsFocus () Application.ResetState (); } - [Fact] public void CanFocus_True_MouseClick_Focuses () { Application.Navigation = new (); + Label label = new () { Text = "label", @@ -1429,6 +1426,7 @@ public void CanFocus_True_MouseClick_Focuses () Y = 0, CanFocus = true }; + View otherView = new () { Text = "view", @@ -1438,6 +1436,7 @@ public void CanFocus_True_MouseClick_Focuses () Height = 1, CanFocus = true }; + Application.Top = new () { Width = 10, @@ -1474,7 +1473,7 @@ public void CanFocus_True_MouseClick_Focuses () [SetupFakeDriver] public void TestLabelUnderscoreMinus () { - var lbl = new Label () + var lbl = new Label { Text = "TextView with some more test_- text. Unicode shouldn't 𝔹Aℝ𝔽!" }; diff --git a/Tests/UnitTests/Views/ListViewTests.cs b/Tests/UnitTests/Views/ListViewTests.cs index 2c9eef2086..0ea7d66e30 100644 --- a/Tests/UnitTests/Views/ListViewTests.cs +++ b/Tests/UnitTests/Views/ListViewTests.cs @@ -1,8 +1,6 @@ using System.Collections; using System.Collections.ObjectModel; using System.Collections.Specialized; -using System.ComponentModel; -using UnitTests; using UnitTests; using Xunit.Abstractions; diff --git a/Tests/UnitTests/Views/MenuBarTests.cs b/Tests/UnitTests/Views/MenuBarTests.cs index 6deae87d4c..3fc6051654 100644 --- a/Tests/UnitTests/Views/MenuBarTests.cs +++ b/Tests/UnitTests/Views/MenuBarTests.cs @@ -1,5 +1,4 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -410,13 +409,13 @@ public void Disabled_MenuItem_Is_Never_Selected () ); Assert.True ( - top.Subviews [1] + top.SubViews.ElementAt (1) .NewMouseEvent ( - new () { Position = new (0, 2), Flags = MouseFlags.Button1Clicked, View = top.Subviews [1] } + new () { Position = new (0, 2), Flags = MouseFlags.Button1Clicked, View = top.SubViews.ElementAt (1) } ) ); - top.Subviews [1].Layout(); - top.Subviews [1].Draw (); + top.SubViews.ElementAt (1).Layout(); + top.SubViews.ElementAt (1).Draw (); DriverAssert.AssertDriverAttributesAre ( @" @@ -433,12 +432,12 @@ top.Subviews [1] ); Assert.True ( - top.Subviews [1] + top.SubViews.ElementAt (1) .NewMouseEvent ( - new () { Position = new (0, 2), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [1] } + new () { Position = new (0, 2), Flags = MouseFlags.ReportMousePosition, View = top.SubViews.ElementAt (1) } ) ); - top.Subviews [1].Draw (); + top.SubViews.ElementAt (1).Draw (); DriverAssert.AssertDriverAttributesAre ( @" @@ -1218,7 +1217,7 @@ .Children [0] Application.Top.Draw (); DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.N)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.N)); Application.MainLoop.RunIteration (); Assert.True (newAction); @@ -1227,7 +1226,7 @@ .Children [0] Application.Top.Draw (); DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.C)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.C)); Application.MainLoop.RunIteration (); Assert.True (copyAction); top.Dispose (); @@ -1979,7 +1978,7 @@ public void MenuBar_In_Window_Without_Other_Views_Without_Top_Init_With_Run_T () output ); - Assert.True (top.Subviews [0].NewKeyDownEvent (Key.CursorRight)); + Assert.True (top.SubViews.ElementAt (0).NewKeyDownEvent (Key.CursorRight)); Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( @@ -1996,7 +1995,7 @@ public void MenuBar_In_Window_Without_Other_Views_Without_Top_Init_With_Run_T () ); Assert.True ( - ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (Key.CursorRight) + ((MenuBar)top.SubViews.ElementAt (0))._openMenu.NewKeyDownEvent (Key.CursorRight) ); top.Draw (); @@ -2014,7 +2013,7 @@ public void MenuBar_In_Window_Without_Other_Views_Without_Top_Init_With_Run_T () ); Assert.True ( - ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (Key.CursorRight) + ((MenuBar)top.SubViews.ElementAt (0))._openMenu.NewKeyDownEvent (Key.CursorRight) ); View.SetClipToScreen (); top.Draw (); @@ -2089,7 +2088,7 @@ public void MenuBar_Position_And_Size_With_HotKeys_Is_The_Same_As_Without_HotKey DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); // Open second - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorRight)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); View.SetClipToScreen (); top.Draw (); @@ -2137,7 +2136,7 @@ public void MenuBar_Position_And_Size_With_HotKeys_Is_The_Same_As_Without_HotKey DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); // Open second - Assert.True (top.Subviews [1].NewKeyDownEvent (Key.CursorRight)); + Assert.True (top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); View.SetClipToScreen (); Application.Top.Draw (); @@ -2844,7 +2843,7 @@ public void RemoveAndThenAddMenuBar_ShouldNotChangeWidth () menuBar2.Visible = true; w.Add (menuBar2); - MenuBar [] menuBars = w.Subviews.OfType ().ToArray (); + MenuBar [] menuBars = w.SubViews.OfType ().ToArray (); Assert.Equal (2, menuBars.Length); Assert.Equal (Dim.Fill (), menuBars [0].Width); @@ -3081,7 +3080,7 @@ public void UseSubMenusSingleFrame_False_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); top.Draw (); expected = @" @@ -3096,7 +3095,7 @@ public void UseSubMenusSingleFrame_False_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (Key.CursorLeft)); + Assert.True (Application.Top.SubViews.ElementAt (2).NewKeyDownEvent (Key.CursorLeft)); top.Draw (); expected = @" @@ -3110,7 +3109,7 @@ public void UseSubMenusSingleFrame_False_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Esc)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.Esc)); top.Draw (); expected = @" @@ -3192,7 +3191,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () menu.NewMouseEvent ( new () { - Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.Top.Subviews [1] + Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.Top.SubViews.ElementAt (1) } ); top.Draw (); @@ -3214,7 +3213,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () menu.NewMouseEvent ( new () { - Position = new (1, 1), Flags = MouseFlags.ReportMousePosition, View = Application.Top.Subviews [1] + Position = new (1, 1), Flags = MouseFlags.ReportMousePosition, View = Application.Top.SubViews.ElementAt (1) } ) ); @@ -3383,8 +3382,8 @@ public void UseSubMenusSingleFrame_True_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Enter)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.Enter)); top.Draw (); expected = @" @@ -3400,7 +3399,7 @@ public void UseSubMenusSingleFrame_True_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 15, 7), pos); - Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (Key.Enter)); + Assert.True (Application.Top.SubViews.ElementAt (2).NewKeyDownEvent (Key.Enter)); top.Draw (); expected = @" @@ -3415,7 +3414,7 @@ public void UseSubMenusSingleFrame_True_By_Keyboard () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Esc)); + Assert.True (Application.Top.SubViews.ElementAt (1).NewKeyDownEvent (Key.Esc)); top.Draw (); expected = @" @@ -3495,7 +3494,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.False (menu.NewMouseEvent (new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] })); + Assert.False (menu.NewMouseEvent (new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.SubViews.ElementAt (1) })); top.Draw (); expected = @" @@ -3511,7 +3510,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 15, 7), pos); - menu.NewMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] }); + menu.NewMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.SubViews.ElementAt (2) }); top.Draw (); expected = @" @@ -3681,7 +3680,7 @@ public void UseSubMenusSingleFrame_True_Without_Border () Assert.Equal (new (1, 0, 8, 4), pos); menu.NewMouseEvent ( - new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] } + new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.SubViews.ElementAt (1) } ); top.Draw (); @@ -3697,7 +3696,7 @@ public void UseSubMenusSingleFrame_True_Without_Border () Assert.Equal (new (1, 0, 13, 5), pos); menu.NewMouseEvent ( - new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] } + new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.SubViews.ElementAt (2) } ); top.Draw (); diff --git a/Tests/UnitTests/Views/ProgressBarTests.cs b/Tests/UnitTests/Views/ProgressBarTests.cs index 2b56360a19..744ce198f9 100644 --- a/Tests/UnitTests/Views/ProgressBarTests.cs +++ b/Tests/UnitTests/Views/ProgressBarTests.cs @@ -32,7 +32,7 @@ public void Fraction_Redraw () pb.BeginInit (); pb.EndInit (); - pb.LayoutSubviews (); + pb.LayoutSubViews (); for (var i = 0; i <= pb.Frame.Width; i++) { @@ -174,7 +174,7 @@ public void Pulse_Redraw_BidirectionalMarquee_False () pb.BeginInit (); pb.EndInit (); - pb.LayoutSubviews (); + pb.LayoutSubViews (); for (var i = 0; i < 38; i++) { @@ -879,7 +879,7 @@ public void Pulse_Redraw_BidirectionalMarquee_True_Default () pb.BeginInit (); pb.EndInit (); - pb.LayoutSubviews (); + pb.LayoutSubViews (); for (var i = 0; i < 38; i++) { diff --git a/Tests/UnitTests/Views/RadioGroupTests.cs b/Tests/UnitTests/Views/RadioGroupTests.cs index c5a9ea92e8..ba143fafc2 100644 --- a/Tests/UnitTests/Views/RadioGroupTests.cs +++ b/Tests/UnitTests/Views/RadioGroupTests.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; // ReSharper disable AccessToModifiedClosure @@ -42,7 +40,7 @@ public void Constructors_Defaults () view.Add (rg); view.BeginInit (); view.EndInit (); - view.LayoutSubviews (); + view.LayoutSubViews (); Assert.True (rg.CanFocus); Assert.Single (rg.RadioLabels); @@ -396,6 +394,7 @@ public void HotKeys_HasFocus_True_Selects () Assert.True (Application.RaiseKeyDownEvent (Key.R.WithAlt)); Assert.Equal (1, rg.SelectedItem); + Application.Top.Remove (rg); var superView = new View (); superView.Add (rg); Assert.True (superView.NewKeyDownEvent (Key.T)); diff --git a/Tests/UnitTests/Views/ScrollBarTests.cs b/Tests/UnitTests/Views/ScrollBarTests.cs index 4cc48f3857..99d0200498 100644 --- a/Tests/UnitTests/Views/ScrollBarTests.cs +++ b/Tests/UnitTests/Views/ScrollBarTests.cs @@ -1,296 +1,15 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; -using static Unix.Terminal.Delegates; namespace Terminal.Gui.ViewsTests; public class ScrollBarTests (ITestOutputHelper output) { - [Fact] - public void Constructor_Defaults () - { - var scrollBar = new ScrollBar (); - Assert.False (scrollBar.CanFocus); - Assert.Equal (Orientation.Vertical, scrollBar.Orientation); - Assert.Equal (0, scrollBar.ScrollableContentSize); - Assert.Equal (0, scrollBar.VisibleContentSize); - Assert.Equal (0, scrollBar.GetSliderPosition ()); - Assert.Equal (0, scrollBar.Position); - Assert.False (scrollBar.AutoShow); - } - - #region AutoHide - [Fact] - [AutoInitShutdown] - public void AutoHide_False_Is_Default_CorrectlyHidesAndShows () - { - var super = new Toplevel () - { - Id = "super", - Width = 1, - Height = 20 - }; - - var scrollBar = new ScrollBar - { - }; - super.Add (scrollBar); - Assert.False (scrollBar.AutoShow); - Assert.True (scrollBar.Visible); - - scrollBar.AutoShow = true; - Assert.True (scrollBar.AutoShow); - Assert.True (scrollBar.Visible); - - RunState rs = Application.Begin (super); - - // Should Show - scrollBar.ScrollableContentSize = 21; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - // Should Hide - scrollBar.ScrollableContentSize = 10; - Assert.False (scrollBar.Visible); - - super.Dispose (); - } - - [Fact] - [AutoInitShutdown] - public void AutoHide_False_CorrectlyHidesAndShows () - { - var super = new Toplevel () - { - Id = "super", - Width = 1, - Height = 20 - }; - - var scrollBar = new ScrollBar - { - ScrollableContentSize = 20, - AutoShow = false - }; - super.Add (scrollBar); - Assert.False (scrollBar.AutoShow); - Assert.True (scrollBar.Visible); - - RunState rs = Application.Begin (super); - - // Should Hide if AutoSize = true, but should not hide if AutoSize = false - scrollBar.ScrollableContentSize = 10; - Assert.True (scrollBar.Visible); - - super.Dispose (); - } - - [Fact] - [AutoInitShutdown] - public void AutoHide_True_Changing_ScrollableContentSize_CorrectlyHidesAndShows () - { - var super = new Toplevel () - { - Id = "super", - Width = 1, - Height = 20 - }; - - var scrollBar = new ScrollBar - { - ScrollableContentSize = 20, - }; - super.Add (scrollBar); - Assert.False (scrollBar.AutoShow); - Assert.True (scrollBar.Visible); - - scrollBar.AutoShow = true; - - RunState rs = Application.Begin (super); - - Assert.False (scrollBar.Visible); - Assert.Equal (1, scrollBar.Frame.Width); - Assert.Equal (20, scrollBar.Frame.Height); - - scrollBar.ScrollableContentSize = 10; - Application.RunIteration (ref rs); - Assert.False (scrollBar.Visible); - - scrollBar.ScrollableContentSize = 30; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - scrollBar.AutoShow = false; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - scrollBar.ScrollableContentSize = 10; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - super.Dispose (); - } - - [Fact] - [AutoInitShutdown] - public void AutoHide_Change_VisibleContentSize_CorrectlyHidesAndShows () - { - var super = new Toplevel () - { - Id = "super", - Width = 1, - Height = 20 - }; - - var scrollBar = new ScrollBar - { - ScrollableContentSize = 20, - VisibleContentSize = 20 - }; - super.Add (scrollBar); - Assert.False (scrollBar.AutoShow); - Assert.True (scrollBar.Visible); - - scrollBar.AutoShow = true; - - RunState rs = Application.Begin (super); - - Assert.Equal (Orientation.Vertical, scrollBar.Orientation); - Assert.Equal (20, scrollBar.VisibleContentSize); - Assert.False (scrollBar.Visible); - - scrollBar.VisibleContentSize = 10; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - scrollBar.VisibleContentSize = 30; - Application.RunIteration (ref rs); - Assert.False (scrollBar.Visible); - - scrollBar.VisibleContentSize = 10; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - scrollBar.VisibleContentSize = 21; - Application.RunIteration (ref rs); - Assert.False (scrollBar.Visible); - - scrollBar.AutoShow = false; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - scrollBar.VisibleContentSize = 10; - Application.RunIteration (ref rs); - Assert.True (scrollBar.Visible); - - super.Dispose (); - } - - #endregion AutoHide - - #region Orientation - [Fact] - public void OnOrientationChanged_Keeps_Size () - { - var scroll = new ScrollBar (); - scroll.Layout (); - scroll.ScrollableContentSize = 1; - - scroll.Orientation = Orientation.Horizontal; - Assert.Equal (1, scroll.ScrollableContentSize); - } - - [Fact] - public void OnOrientationChanged_Sets_Position_To_0 () - { - View super = new View () - { - Id = "super", - Width = 10, - Height = 10 - }; - var scrollBar = new ScrollBar () - { - }; - super.Add (scrollBar); - scrollBar.Layout (); - scrollBar.Position = 1; - scrollBar.Orientation = Orientation.Horizontal; - - Assert.Equal (0, scrollBar.GetSliderPosition ()); - } - - #endregion Orientation - - - #region Size - - // TODO: Add tests. - - #endregion Size - - #region Position - [Fact] - public void Position_Event_Cancels () - { - var changingCount = 0; - var changedCount = 0; - var scrollBar = new ScrollBar { }; - scrollBar.ScrollableContentSize = 5; - scrollBar.Frame = new Rectangle (0, 0, 1, 4); // Needs to be at least 4 for slider to move - - scrollBar.PositionChanging += (s, e) => - { - if (changingCount == 0) - { - e.Cancel = true; - } - - changingCount++; - }; - scrollBar.PositionChanged += (s, e) => changedCount++; - - scrollBar.Position = 1; - Assert.Equal (0, scrollBar.Position); - Assert.Equal (1, changingCount); - Assert.Equal (0, changedCount); - - scrollBar.Position = 1; - Assert.Equal (1, scrollBar.Position); - Assert.Equal (2, changingCount); - Assert.Equal (1, changedCount); - } - #endregion Position - - - [Fact] - public void ScrollableContentSize_Cannot_Be_Negative () - { - var scrollBar = new ScrollBar { Height = 10, ScrollableContentSize = -1 }; - Assert.Equal (0, scrollBar.ScrollableContentSize); - scrollBar.ScrollableContentSize = -10; - Assert.Equal (0, scrollBar.ScrollableContentSize); - } - - [Fact] - public void ScrollableContentSizeChanged_Event () - { - var count = 0; - var scrollBar = new ScrollBar (); - scrollBar.ScrollableContentSizeChanged += (s, e) => count++; - - scrollBar.ScrollableContentSize = 10; - Assert.Equal (10, scrollBar.ScrollableContentSize); - Assert.Equal (1, count); - } + #region Draw [Theory] [SetupFakeDriver] - #region Draw - - #region Horizontal #region Super 10 - ScrollBar 8 @@ -809,9 +528,7 @@ public void Draws_Correctly_Default_Settings (int width, int height, int content #endregion Draw #region Mouse - - - + [Theory] [CombinatorialData] [AutoInitShutdown] diff --git a/Tests/UnitTests/Views/ScrollSliderTests.cs b/Tests/UnitTests/Views/ScrollSliderTests.cs index 2e94d4b3e7..445f9bcf70 100644 --- a/Tests/UnitTests/Views/ScrollSliderTests.cs +++ b/Tests/UnitTests/Views/ScrollSliderTests.cs @@ -1,682 +1,10 @@ -using System.Diagnostics; -using System.Runtime.InteropServices; -using Microsoft.VisualStudio.TestPlatform.Utilities; -using UnitTests; -using UnitTests; +using UnitTests; using Xunit.Abstractions; -using static Unix.Terminal.Delegates; namespace Terminal.Gui.ViewsTests; public class ScrollSliderTests (ITestOutputHelper output) { - - [Fact] - public void Constructor_Initializes_Correctly () - { - var scrollSlider = new ScrollSlider (); - Assert.False (scrollSlider.CanFocus); - Assert.Equal (Orientation.Vertical, scrollSlider.Orientation); - Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection); - Assert.Equal (Alignment.Center, scrollSlider.TextAlignment); - Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment); - scrollSlider.Layout (); - Assert.Equal (0, scrollSlider.Frame.X); - Assert.Equal (0, scrollSlider.Frame.Y); - Assert.Equal (1, scrollSlider.Size); - Assert.Equal (2048, scrollSlider.VisibleContentSize); - } - - [Fact] - public void Add_To_SuperView_Initializes_Correctly () - { - View super = new View () - { - Id = "super", - Width = 10, - Height = 10, - CanFocus = true - }; - var scrollSlider = new ScrollSlider (); - super.Add (scrollSlider); - - Assert.False (scrollSlider.CanFocus); - Assert.Equal (Orientation.Vertical, scrollSlider.Orientation); - Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection); - Assert.Equal (Alignment.Center, scrollSlider.TextAlignment); - Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment); - scrollSlider.Layout (); - Assert.Equal (0, scrollSlider.Frame.X); - Assert.Equal (0, scrollSlider.Frame.Y); - Assert.Equal (1, scrollSlider.Size); - Assert.Equal (10, scrollSlider.VisibleContentSize); - } - - //[Fact] - //public void OnOrientationChanged_Sets_Size_To_1 () - //{ - // var scrollSlider = new ScrollSlider (); - // scrollSlider.Orientation = Orientation.Horizontal; - // Assert.Equal (1, scrollSlider.Size); - //} - - [Fact] - public void OnOrientationChanged_Sets_Position_To_0 () - { - View super = new View () - { - Id = "super", - Width = 10, - Height = 10 - }; - var scrollSlider = new ScrollSlider () - { - }; - super.Add (scrollSlider); - scrollSlider.Layout (); - scrollSlider.Position = 1; - scrollSlider.Orientation = Orientation.Horizontal; - - Assert.Equal (0, scrollSlider.Position); - } - - [Fact] - public void OnOrientationChanged_Updates_TextDirection_And_TextAlignment () - { - var scrollSlider = new ScrollSlider (); - scrollSlider.Orientation = Orientation.Horizontal; - Assert.Equal (TextDirection.LeftRight_TopBottom, scrollSlider.TextDirection); - Assert.Equal (Alignment.Center, scrollSlider.TextAlignment); - Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment); - } - - [Theory] - [CombinatorialData] - public void Size_Clamps_To_SuperView_Viewport ([CombinatorialRange (-1, 6, 1)] int sliderSize, Orientation orientation) - { - var super = new View - { - Id = "super", - Width = 5, - Height = 5 - }; - - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - }; - super.Add (scrollSlider); - scrollSlider.Layout (); - - scrollSlider.Size = sliderSize; - scrollSlider.Layout (); - - Assert.True (scrollSlider.Size > 0); - - Assert.True (scrollSlider.Size <= 5); - } - - - [Theory] - [CombinatorialData] - public void Size_Clamps_To_VisibleContentSizes ([CombinatorialRange (1, 6, 1)] int dimension, [CombinatorialRange (-1, 6, 1)] int sliderSize, Orientation orientation) - { - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - Size = sliderSize, - }; - scrollSlider.Layout (); - - Assert.True (scrollSlider.Size > 0); - - Assert.True (scrollSlider.Size <= dimension); - } - - - [Theory] - [CombinatorialData] - - public void CalculateSize_ScrollBounds_0_Returns_1 ([CombinatorialRange (-1, 5, 1)] int visibleContentSize, [CombinatorialRange (-1, 5, 1)] int scrollableContentSize) - { - // Arrange - - // Act - var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, 0); - - // Assert - Assert.Equal (1, sliderSize); - } - - [Theory] - [CombinatorialData] - - public void CalculateSize_ScrollableContentSize_0_Returns_1 ([CombinatorialRange (-1, 5, 1)] int visibleContentSize, [CombinatorialRange (-1, 5, 1)] int sliderBounds) - { - // Arrange - - // Act - var sliderSize = ScrollSlider.CalculateSize (0, visibleContentSize, sliderBounds); - - // Assert - Assert.Equal (1, sliderSize); - } - - - //[Theory] - //[CombinatorialData] - - //public void CalculateSize_VisibleContentSize_0_Returns_0 ([CombinatorialRange (-1, 5, 1)] int scrollableContentSize, [CombinatorialRange (-1, 5, 1)] int sliderBounds) - //{ - // // Arrange - - // // Act - // var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, 0, sliderBounds); - - // // Assert - // Assert.Equal (0, sliderSize); - //} - - - [Theory] - [InlineData (0, 1, 1, 1)] - [InlineData (1, 1, 1, 1)] - [InlineData (1, 2, 1, 1)] - [InlineData (0, 5, 5, 5)] - [InlineData (1, 5, 5, 1)] - [InlineData (2, 5, 5, 2)] - [InlineData (3, 5, 5, 3)] - [InlineData (4, 5, 5, 4)] - [InlineData (5, 5, 5, 5)] - [InlineData (6, 5, 5, 5)] - public void CalculateSize_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int scrollBounds, int expectedSliderSize) - { - // Arrange - - // Act - var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, scrollBounds); - - // Assert - Assert.Equal (expectedSliderSize, sliderSize); - } - - [Fact] - public void VisibleContentSize_Not_Set_Uses_SuperView () - { - View super = new () - { - Id = "super", - Height = 5, - Width = 5, - }; - var scrollSlider = new ScrollSlider - { - }; - - super.Add (scrollSlider); - super.Layout (); - Assert.Equal (5, scrollSlider.VisibleContentSize); - } - - [Fact] - public void VisibleContentSize_Set_Overrides_SuperView () - { - View super = new () - { - Id = "super", - Height = 5, - Width = 5, - }; - var scrollSlider = new ScrollSlider - { - VisibleContentSize = 10, - }; - - super.Add (scrollSlider); - super.Layout (); - Assert.Equal (10, scrollSlider.VisibleContentSize); - - super.Height = 3; - super.Layout (); - Assert.Equal (10, scrollSlider.VisibleContentSize); - - super.Height = 7; - super.Layout (); - Assert.Equal (10, scrollSlider.VisibleContentSize); - - } - - [Theory] - [CombinatorialData] - public void VisibleContentSizes_Clamps_0_To_Dimension ([CombinatorialRange (0, 10, 1)] int dimension, Orientation orientation) - { - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - }; - - Assert.InRange (scrollSlider.VisibleContentSize, 1, 10); - - View super = new () - { - Id = "super", - Height = dimension, - Width = dimension, - }; - - scrollSlider = new ScrollSlider - { - Orientation = orientation, - }; - super.Add (scrollSlider); - super.Layout (); - - Assert.InRange (scrollSlider.VisibleContentSize, 1, 10); - - scrollSlider.VisibleContentSize = dimension; - - Assert.InRange (scrollSlider.VisibleContentSize, 1, 10); - } - - [Theory] - //// 0123456789 - //// --------- - //// ◄█► - //[InlineData (3, 3, 0, 1, 0)] - //[InlineData (3, 3, 1, 1, 0)] - //[InlineData (3, 3, 2, 1, 0)] - - //// 0123456789 - //// --------- - //// ◄██► - //[InlineData (4, 4, 0, 2, 0)] - //[InlineData (4, 4, 1, 2, 0)] - //[InlineData (4, 4, 2, 2, 0)] - //[InlineData (4, 4, 3, 2, 0)] - //[InlineData (4, 4, 4, 2, 0)] - - // 012345 - // ^---- - // █░ - [InlineData (2, 5, 0, 0)] - // -^--- - // █░ - [InlineData (2, 5, 1, 0)] - // --^-- - // ░█ - [InlineData (2, 5, 2, 1)] - // ---^- - // ░█ - [InlineData (2, 5, 3, 1)] - // ----^ - // ░█ - [InlineData (2, 5, 4, 1)] - - // 012345 - // ^---- - // █░░ - [InlineData (3, 5, 0, 0)] - // -^--- - // ░█░ - [InlineData (3, 5, 1, 1)] - // --^-- - // ░░█ - [InlineData (3, 5, 2, 2)] - // ---^- - // ░░█ - [InlineData (3, 5, 3, 2)] - // ----^ - // ░░█ - [InlineData (3, 5, 4, 2)] - - - // 0123456789 - // ^----- - // █░░ - [InlineData (3, 6, 0, 0)] - // -^---- - // █░░ - [InlineData (3, 6, 1, 1)] - // --^--- - // ░█░ - [InlineData (3, 6, 2, 1)] - // ---^-- - // ░░█ - [InlineData (3, 6, 3, 2)] - // ----^- - // ░░█ - [InlineData (3, 6, 4, 2)] - - // -----^ - // ░░█ - [InlineData (3, 6, 5, 2)] - - // 012345 - // ^---- - // ███░ - [InlineData (4, 5, 0, 0)] - // -^--- - // ░███ - [InlineData (4, 5, 1, 1)] - // --^-- - // ░███ - [InlineData (4, 5, 2, 1)] - // ---^- - // ░███ - [InlineData (4, 5, 3, 1)] - // ----^ - // ░███ - [InlineData (4, 5, 4, 1)] - - //// 01234 - //// ^--------- - //// ◄█░░► - //[InlineData (5, 10, 0, 1, 0)] - //// -^-------- - //// ◄█░░► - //[InlineData (5, 10, 1, 1, 0)] - //// --^------- - //// ◄█░░► - //[InlineData (5, 10, 2, 1, 0)] - //// ---^------ - //// ◄█░░► - //[InlineData (5, 10, 3, 1, 0)] - //// ----^---- - //// ◄░█░► - //[InlineData (5, 10, 4, 1, 1)] - //// -----^--- - //// ◄░█░► - //[InlineData (5, 10, 5, 1, 1)] - //// ------^-- - //// ◄░░█► - //[InlineData (5, 10, 6, 1, 2)] - //// ------^-- - //// ◄░░█► - //[InlineData (5, 10, 7, 1, 2)] - //// -------^- - //// ◄░░█► - //[InlineData (5, 10, 8, 1, 2)] - //// --------^ - //// ◄░░█► - //[InlineData (5, 10, 9, 1, 2)] - - // 0123456789 - // ████░░░░ - // ^----------------- - // 012345678901234567890123456789 - // ░████░░░ - // ----^------------- - // 012345678901234567890123456789 - // ░░████░░ - // --------^--------- - // 012345678901234567890123456789 - // ░░░████░ - // ------------^----- - // 012345678901234567890123456789 - // ░░░░████ - // ----------------^-- - - - - // 0123456789 - // ███░░░░░ - // ^----------------- - - // 012345678901234567890123456789 - // ░░███░░░ - // --------^--------- - // 012345678901234567890123456789 - // ░░░███░░ - // ------------^----- - // 012345678901234567890123456789 - // ░░░░███░ - // ----------------^-- - // 012345678901234567890123456789 - // ░░░░░███ - // ----------------^-- - - - [InlineData (8, 18, 0, 0)] - [InlineData (8, 18, 1, 0)] - // 012345678901234567890123456789 - // ░███░░░░ - // --^--------------- - [InlineData (8, 18, 2, 1)] - [InlineData (8, 18, 3, 2)] - [InlineData (8, 18, 4, 2)] - [InlineData (8, 18, 5, 2)] - [InlineData (8, 18, 6, 3)] - [InlineData (8, 18, 7, 4)] - [InlineData (8, 18, 8, 4)] - [InlineData (8, 18, 9, 4)] - - // 012345678901234567890123456789 - // ░░░░░███ - // ----------^-------- - [InlineData (8, 18, 10, 5)] - [InlineData (8, 18, 11, 5)] - [InlineData (8, 18, 12, 5)] - [InlineData (8, 18, 13, 5)] - [InlineData (8, 18, 14, 5)] - [InlineData (8, 18, 15, 5)] - [InlineData (8, 18, 16, 5)] - [InlineData (8, 18, 17, 5)] - [InlineData (8, 18, 18, 5)] - [InlineData (8, 18, 19, 5)] - [InlineData (8, 18, 20, 5)] - [InlineData (8, 18, 21, 5)] - [InlineData (8, 18, 22, 5)] - [InlineData (8, 18, 23, 5)] - // ------------------ ^ - [InlineData (8, 18, 24, 5)] - [InlineData (8, 18, 25, 5)] - - //// 0123456789 - //// ◄████░░░░► - //// ^----------------- - //[InlineData (10, 20, 0, 5, 0)] - //[InlineData (10, 20, 1, 5, 0)] - //[InlineData (10, 20, 2, 5, 0)] - //[InlineData (10, 20, 3, 5, 0)] - //[InlineData (10, 20, 4, 5, 1)] - //[InlineData (10, 20, 5, 5, 1)] - //[InlineData (10, 20, 6, 5, 1)] - //[InlineData (10, 20, 7, 5, 2)] - //[InlineData (10, 20, 8, 5, 2)] - //[InlineData (10, 20, 9, 5, 2)] - //[InlineData (10, 20, 10, 5, 3)] - //[InlineData (10, 20, 11, 5, 3)] - //[InlineData (10, 20, 12, 5, 3)] - //[InlineData (10, 20, 13, 5, 3)] - //[InlineData (10, 20, 14, 5, 4)] - //[InlineData (10, 20, 15, 5, 4)] - //[InlineData (10, 20, 16, 5, 4)] - //[InlineData (10, 20, 17, 5, 5)] - //[InlineData (10, 20, 18, 5, 5)] - //[InlineData (10, 20, 19, 5, 5)] - //[InlineData (10, 20, 20, 5, 6)] - //[InlineData (10, 20, 21, 5, 6)] - //[InlineData (10, 20, 22, 5, 6)] - //[InlineData (10, 20, 23, 5, 6)] - //[InlineData (10, 20, 24, 5, 6)] - //[InlineData (10, 20, 25, 5, 6)] - - public void CalculatePosition_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int contentPosition, int expectedSliderPosition) - { - // Arrange - - // Act - var sliderPosition = ScrollSlider.CalculatePosition ( - scrollableContentSize: scrollableContentSize, - visibleContentSize: visibleContentSize, - contentPosition: contentPosition, - sliderBounds: visibleContentSize, - NavigationDirection.Forward); - - // Assert - Assert.Equal (expectedSliderPosition, sliderPosition); - } - - [Theory] - [InlineData (8, 18, 0, 0)] - - public void CalculateContentPosition_Calculates_Correctly ( - int visibleContentSize, - int scrollableContentSize, - int sliderPosition, - int expectedContentPosition - ) - { - // Arrange - - // Act - var contentPosition = ScrollSlider.CalculateContentPosition ( - scrollableContentSize: scrollableContentSize, - visibleContentSize: visibleContentSize, - sliderPosition: sliderPosition, - sliderBounds: visibleContentSize); - - // Assert - Assert.Equal (expectedContentPosition, contentPosition); - } - - - [Theory] - [CombinatorialData] - public void ClampPosition_WithSuperView_Clamps_To_ViewPort_Minus_Size_If_VisibleContentSize_Not_Set ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation) - { - View super = new () - { - Id = "super", - Height = dimension, - Width = dimension, - }; - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - Size = sliderSize, - }; - super.Add (scrollSlider); - super.Layout (); - - Assert.Equal (dimension, scrollSlider.VisibleContentSize); - - int clampedPosition = scrollSlider.ClampPosition (sliderPosition); - - Assert.InRange (clampedPosition, 0, dimension - sliderSize); - } - - [Theory] - [CombinatorialData] - public void ClampPosition_WithSuperView_Clamps_To_VisibleContentSize_Minus_Size ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation) - { - View super = new () - { - Id = "super", - Height = dimension + 2, - Width = dimension + 2, - }; - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - Size = sliderSize, - }; - super.Add (scrollSlider); - super.Layout (); - - int clampedPosition = scrollSlider.ClampPosition (sliderPosition); - - Assert.InRange (clampedPosition, 0, dimension - sliderSize); - } - - [Theory] - [CombinatorialData] - public void ClampPosition_NoSuperView_Clamps_To_VisibleContentSize_Minus_Size ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation) - { - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - Size = sliderSize, - }; - - int clampedPosition = scrollSlider.ClampPosition (sliderPosition); - - Assert.InRange (clampedPosition, 0, dimension - sliderSize); - } - - [Theory] - [CombinatorialData] - public void Position_Clamps_To_VisibleContentSize ([CombinatorialRange (0, 5, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation) - { - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - Size = sliderSize, - Position = sliderPosition - }; - - Assert.True (scrollSlider.Position <= 5); - } - - - [Theory] - [CombinatorialData] - public void Position_Clamps_To_SuperView_Viewport ([CombinatorialRange (0, 5, 1)] int sliderSize, [CombinatorialRange (-2, 10, 2)] int sliderPosition, Orientation orientation) - { - var super = new View - { - Id = "super", - Width = 5, - Height = 5 - }; - - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - }; - super.Add (scrollSlider); - scrollSlider.Size = sliderSize; - scrollSlider.Layout (); - - scrollSlider.Position = sliderPosition; - - Assert.True (scrollSlider.Position <= 5); - } - - - [Theory] - [CombinatorialData] - public void Position_Clamps_To_VisibleContentSize_With_SuperView ([CombinatorialRange (0, 5, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-2, 10, 2)] int sliderPosition, Orientation orientation) - { - var super = new View - { - Id = "super", - Width = 10, - Height = 10 - }; - - var scrollSlider = new ScrollSlider - { - Orientation = orientation, - VisibleContentSize = dimension, - Size = sliderSize, - Position = sliderPosition - }; - - super.Add (scrollSlider); - scrollSlider.Size = sliderSize; - scrollSlider.Layout (); - - scrollSlider.Position = sliderPosition; - - Assert.True (scrollSlider.Position <= 5); - } - [Theory] [SetupFakeDriver] [InlineData ( diff --git a/Tests/UnitTests/Views/ShortcutTests.cs b/Tests/UnitTests/Views/ShortcutTests.cs index e9c0edfebe..a127d9eb2f 100644 --- a/Tests/UnitTests/Views/ShortcutTests.cs +++ b/Tests/UnitTests/Views/ShortcutTests.cs @@ -6,442 +6,6 @@ namespace Terminal.Gui.ViewsTests; [TestSubject (typeof (Shortcut))] public class ShortcutTests { - [Fact] - public void Constructor_Defaults () - { - var shortcut = new Shortcut (); - - Assert.NotNull (shortcut); - Assert.True (shortcut.CanFocus); - Assert.IsType (shortcut.Width); - Assert.IsType (shortcut.Height); - } - - [Fact] - public void Size_Defaults () - { - var shortcut = new Shortcut (); - shortcut.Layout (); - - Assert.Equal (2, shortcut.Frame.Width); - Assert.Equal (1, shortcut.Frame.Height); - Assert.Equal (2, shortcut.Viewport.Width); - Assert.Equal (1, shortcut.Viewport.Height); - - Assert.Equal (0, shortcut.CommandView.Viewport.Width); - Assert.Equal (1, shortcut.CommandView.Viewport.Height); - - Assert.Equal (0, shortcut.HelpView.Viewport.Width); - Assert.Equal (0, shortcut.HelpView.Viewport.Height); - - Assert.Equal (0, shortcut.KeyView.Viewport.Width); - Assert.Equal (0, shortcut.KeyView.Viewport.Height); - - // 0123456789 - // " 0 A " - shortcut = new () - { - Key = Key.A, - HelpText = "0" - }; - shortcut.Layout (); - Assert.Equal (8, shortcut.Frame.Width); - Assert.Equal (1, shortcut.Frame.Height); - Assert.Equal (8, shortcut.Viewport.Width); - Assert.Equal (1, shortcut.Viewport.Height); - - Assert.Equal (0, shortcut.CommandView.Viewport.Width); - Assert.Equal (1, shortcut.CommandView.Viewport.Height); - - Assert.Equal (1, shortcut.HelpView.Viewport.Width); - Assert.Equal (1, shortcut.HelpView.Viewport.Height); - - Assert.Equal (1, shortcut.KeyView.Viewport.Width); - Assert.Equal (1, shortcut.KeyView.Viewport.Height); - - // 0123456789 - // " C 0 A " - shortcut = new () - { - Title = "C", - Key = Key.A, - HelpText = "0" - }; - shortcut.Layout (); - Assert.Equal (9, shortcut.Frame.Width); - Assert.Equal (1, shortcut.Frame.Height); - Assert.Equal (9, shortcut.Viewport.Width); - Assert.Equal (1, shortcut.Viewport.Height); - - Assert.Equal (1, shortcut.CommandView.Viewport.Width); - Assert.Equal (1, shortcut.CommandView.Viewport.Height); - - Assert.Equal (1, shortcut.HelpView.Viewport.Width); - Assert.Equal (1, shortcut.HelpView.Viewport.Height); - - Assert.Equal (1, shortcut.KeyView.Viewport.Width); - Assert.Equal (1, shortcut.KeyView.Viewport.Height); - } - - [Theory] - [InlineData ("", "", KeyCode.Null, 2)] - [InlineData ("C", "", KeyCode.Null, 3)] - [InlineData ("", "H", KeyCode.Null, 5)] - [InlineData ("", "", KeyCode.K, 5)] - [InlineData ("C", "", KeyCode.K, 6)] - [InlineData ("C", "H", KeyCode.Null, 6)] - [InlineData ("", "H", KeyCode.K, 8)] - [InlineData ("C", "H", KeyCode.K, 9)] - public void NaturalSize (string command, string help, KeyCode key, int expectedWidth) - { - var shortcut = new Shortcut - { - HelpText = help, - Key = key, - Title = command, - }; - - shortcut.Layout (); - - // |0123456789 - // | C H K | - Assert.Equal (expectedWidth, shortcut.Frame.Width); - - shortcut = new Shortcut - { - HelpText = help, - Title = command, - Key = key - }; - - shortcut.Layout (); - Assert.Equal (expectedWidth, shortcut.Frame.Width); - - shortcut = new Shortcut - { - HelpText = help, - Key = key, - Title = command, - }; - - shortcut.Layout (); - Assert.Equal (expectedWidth, shortcut.Frame.Width); - - shortcut = new Shortcut - { - Key = key, - HelpText = help, - Title = command, - }; - - shortcut.Layout (); - Assert.Equal (expectedWidth, shortcut.Frame.Width); - - } - - - - [Theory] - [InlineData (0, 0, 3, 3)] - [InlineData (1, 0, 3, 3)] - [InlineData (2, 0, 3, 3)] - [InlineData (3, 0, 3, 3)] - [InlineData (4, 0, 3, 3)] - [InlineData (5, 0, 3, 3)] - [InlineData (6, 0, 3, 3)] - [InlineData (7, 0, 3, 4)] - [InlineData (8, 0, 3, 5)] - [InlineData (9, 0, 3, 6)] - [InlineData (10, 0, 4, 7)] - [InlineData (11, 0, 5, 8)] - public void Set_Width_Layouts_Correctly (int width, int expectedCmdX, int expectedHelpX, int expectedKeyX) - { - var shortcut = new Shortcut - { - Width = width, - Title = "C", - Text = "H", - Key = Key.K - }; - shortcut.Layout (); - - // 01234 - // -C--K - - // 012345 - // -C--K- - - // 0123456 - // -C-H-K- - - // 01234567 - // -C--H-K- - - // 012345678 - // -C--H--K- - - // 0123456789 - // -C--H--K- - Assert.Equal (expectedCmdX, shortcut.CommandView.Frame.X); - Assert.Equal (expectedHelpX, shortcut.HelpView.Frame.X); - Assert.Equal (expectedKeyX, shortcut.KeyView.Frame.X); - } - - [Fact] - public void CommandView_Text_And_Title_Track () - { - var shortcut = new Shortcut - { - Title = "T" - }; - - Assert.Equal (shortcut.Title, shortcut.CommandView.Text); - - shortcut = new (); - - shortcut.CommandView = new () - { - Text = "T" - }; - Assert.Equal (shortcut.Title, shortcut.CommandView.Text); - } - - [Fact] - public void HelpText_And_Text_Are_The_Same () - { - var shortcut = new Shortcut - { - Text = "H" - }; - - Assert.Equal (shortcut.Text, shortcut.HelpText); - - shortcut = new () - { - HelpText = "H" - }; - - Assert.Equal (shortcut.Text, shortcut.HelpText); - } - - [Theory] - [InlineData (KeyCode.Null, "")] - [InlineData (KeyCode.F1, "F1")] - public void KeyView_Text_Tracks_Key (KeyCode key, string expected) - { - var shortcut = new Shortcut - { - Key = key - }; - - Assert.Equal (expected, shortcut.KeyView.Text); - } - - // Test Key - [Fact] - public void Key_Defaults_To_Empty () - { - var shortcut = new Shortcut (); - - Assert.Equal (Key.Empty, shortcut.Key); - } - - [Fact] - public void Key_Can_Be_Set () - { - var shortcut = new Shortcut (); - - shortcut.Key = Key.F1; - - Assert.Equal (Key.F1, shortcut.Key); - } - - [Fact] - public void Key_Can_Be_Set_To_Empty () - { - var shortcut = new Shortcut (); - - shortcut.Key = Key.Empty; - - Assert.Equal (Key.Empty, shortcut.Key); - } - - [Fact] - public void Key_Set_Binds_Key_To_CommandView_Accept () - { - var shortcut = new Shortcut (); - - shortcut.Key = Key.F1; - - // TODO: - } - - [Fact] - public void Key_Changing_Removes_Previous_Binding () - { - var shortcut = new Shortcut (); - - shortcut.Key = Key.A; - Assert.True (shortcut.HotKeyBindings.TryGet (Key.A, out _)); - - shortcut.Key = Key.B; - Assert.False (shortcut.HotKeyBindings.TryGet (Key.A, out _)); - Assert.True (shortcut.HotKeyBindings.TryGet (Key.B, out _)); - } - - // Test Key gets bound correctly - [Fact] - public void BindKeyToApplication_Defaults_To_HotKey () - { - var shortcut = new Shortcut (); - - Assert.False (shortcut.BindKeyToApplication); - } - - [Fact] - public void BindKeyToApplication_Can_Be_Set () - { - var shortcut = new Shortcut (); - - shortcut.BindKeyToApplication = true; - - Assert.True (shortcut.BindKeyToApplication); - } - - [Fact] - public void BindKeyToApplication_Changing_Adjusts_KeyBindings () - { - var shortcut = new Shortcut (); - - shortcut.Key = Key.A; - Assert.True (shortcut.HotKeyBindings.TryGet (Key.A, out _)); - - shortcut.BindKeyToApplication = true; - Assert.False (shortcut.HotKeyBindings.TryGet (Key.A, out _)); - Assert.True (Application.KeyBindings.TryGet (Key.A, out _)); - - shortcut.BindKeyToApplication = false; - Assert.True (shortcut.HotKeyBindings.TryGet (Key.A, out _)); - Assert.False (Application.KeyBindings.TryGet (Key.A, out _)); - } - - [Theory] - [InlineData (Orientation.Horizontal)] - [InlineData (Orientation.Vertical)] - public void Orientation_SetsCorrectly (Orientation orientation) - { - var shortcut = new Shortcut - { - Orientation = orientation - }; - - Assert.Equal (orientation, shortcut.Orientation); - } - - [Theory] - [InlineData (AlignmentModes.StartToEnd)] - [InlineData (AlignmentModes.EndToStart)] - public void AlignmentModes_SetsCorrectly (AlignmentModes alignmentModes) - { - var shortcut = new Shortcut - { - AlignmentModes = alignmentModes - }; - - Assert.Equal (alignmentModes, shortcut.AlignmentModes); - } - - [Fact] - public void Action_SetsAndGetsCorrectly () - { - var actionInvoked = false; - - var shortcut = new Shortcut - { - Action = () => { actionInvoked = true; } - }; - - shortcut.Action.Invoke (); - - Assert.True (actionInvoked); - } - - [Fact] - public void Subview_Visibility_Controlled_By_Removal () - { - var shortcut = new Shortcut (); - - Assert.True (shortcut.CommandView.Visible); - Assert.Contains (shortcut.CommandView, shortcut.Subviews); - Assert.True (shortcut.HelpView.Visible); - Assert.DoesNotContain (shortcut.HelpView, shortcut.Subviews); - Assert.True (shortcut.KeyView.Visible); - Assert.DoesNotContain (shortcut.KeyView, shortcut.Subviews); - - shortcut.HelpText = "help"; - Assert.True (shortcut.HelpView.Visible); - Assert.Contains (shortcut.HelpView, shortcut.Subviews); - Assert.True (shortcut.KeyView.Visible); - Assert.DoesNotContain (shortcut.KeyView, shortcut.Subviews); - - shortcut.Key = Key.A; - Assert.True (shortcut.HelpView.Visible); - Assert.Contains (shortcut.HelpView, shortcut.Subviews); - Assert.True (shortcut.KeyView.Visible); - Assert.Contains (shortcut.KeyView, shortcut.Subviews); - - shortcut.HelpView.Visible = false; - shortcut.ShowHide (); - Assert.False (shortcut.HelpView.Visible); - Assert.DoesNotContain (shortcut.HelpView, shortcut.Subviews); - Assert.True (shortcut.KeyView.Visible); - Assert.Contains (shortcut.KeyView, shortcut.Subviews); - - shortcut.KeyView.Visible = false; - shortcut.ShowHide (); - Assert.False (shortcut.HelpView.Visible); - Assert.DoesNotContain (shortcut.HelpView, shortcut.Subviews); - Assert.False (shortcut.KeyView.Visible); - Assert.DoesNotContain (shortcut.KeyView, shortcut.Subviews); - } - - [Fact] - public void Focus_CanFocus_Default_Is_True () - { - Shortcut shortcut = new (); - shortcut.Key = Key.A; - shortcut.Text = "Help"; - shortcut.Title = "Command"; - Assert.True (shortcut.CanFocus); - Assert.False (shortcut.CommandView.CanFocus); - } - - [Fact] - public void Focus_CanFocus_CommandView_Add_Tracks () - { - Shortcut shortcut = new (); - Assert.True (shortcut.CanFocus); - Assert.False (shortcut.CommandView.CanFocus); - - shortcut.CommandView = new () { CanFocus = true }; - Assert.False (shortcut.CommandView.CanFocus); - - shortcut.CommandView.CanFocus = true; - Assert.True (shortcut.CommandView.CanFocus); - - shortcut.CanFocus = false; - Assert.False (shortcut.CanFocus); - Assert.True (shortcut.CommandView.CanFocus); - - shortcut.CommandView.CanFocus = false; - Assert.False (shortcut.CanFocus); - Assert.False (shortcut.CommandView.CanFocus); - - shortcut.CommandView.CanFocus = true; - Assert.False (shortcut.CanFocus); - Assert.True (shortcut.CommandView.CanFocus); - } - [Theory] // 0123456789 @@ -531,7 +95,7 @@ int expectedShortcutSelected Application.Top.Add (shortcut); Application.Top.SetRelativeLayout (new (100, 100)); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); Application.RaiseMouseEvent ( new () @@ -585,7 +149,7 @@ public void MouseClick_Button_CommandView_Raises_Shortcut_Accepted (int mouseX, shortcut.CommandView.Accepting += (s, e) => { buttonAccepted++; }; Application.Top.Add (shortcut); Application.Top.SetRelativeLayout (new (100, 100)); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); var accepted = 0; shortcut.Accepting += (s, e) => { accepted++; }; @@ -650,7 +214,7 @@ public void MouseClick_CheckBox_CommandView_Raises_Shortcut_Accepted_Selected_Co Application.Top.Add (shortcut); Application.Top.SetRelativeLayout (new (100, 100)); - Application.Top.LayoutSubviews (); + Application.Top.LayoutSubViews (); var selected = 0; shortcut.Selecting += (s, e) => @@ -888,19 +452,6 @@ public void KeyDown_App_Scope_Invokes_Action (bool canFocus, KeyCode key, int ex Application.ResetState (true); } - [Fact] - public void ColorScheme_SetsAndGetsCorrectly () - { - var colorScheme = new ColorScheme (); - - var shortcut = new Shortcut - { - ColorScheme = colorScheme - }; - - Assert.Same (colorScheme, shortcut.ColorScheme); - } - // https://github.com/gui-cs/Terminal.Gui/issues/3664 [Fact] public void ColorScheme_SetColorScheme_Does_Not_Fault_3664 () diff --git a/Tests/UnitTests/Views/SliderTests.cs b/Tests/UnitTests/Views/SliderTests.cs index eaab6ba699..69c56e593e 100644 --- a/Tests/UnitTests/Views/SliderTests.cs +++ b/Tests/UnitTests/Views/SliderTests.cs @@ -521,7 +521,7 @@ private void DimAuto_Both_Respects_SuperView_ContentSize () view.SetContentSize (new (1, 1)); - view.LayoutSubviews (); + view.LayoutSubViews (); slider.SetRelativeLayout (view.Viewport.Size); Assert.Equal (expectedSize, slider.Frame.Size); @@ -554,7 +554,7 @@ private void DimAuto_Width_Respects_SuperView_ContentSize () view.SetContentSize (new (1, 1)); - view.LayoutSubviews (); + view.LayoutSubViews (); slider.SetRelativeLayout (view.Viewport.Size); Assert.Equal (expectedSize, slider.Frame.Size); @@ -587,7 +587,7 @@ private void DimAuto_Height_Respects_SuperView_ContentSize () view.SetContentSize (new (1, 1)); - view.LayoutSubviews (); + view.LayoutSubViews (); slider.SetRelativeLayout (view.Viewport.Size); Assert.Equal (expectedSize, slider.Frame.Size); diff --git a/Tests/UnitTests/Views/SpinnerViewTests.cs b/Tests/UnitTests/Views/SpinnerViewTests.cs index bd2a116cde..24dc88a422 100644 --- a/Tests/UnitTests/Views/SpinnerViewTests.cs +++ b/Tests/UnitTests/Views/SpinnerViewTests.cs @@ -1,14 +1,10 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; -public class SpinnerViewTests +public class SpinnerViewTests (ITestOutputHelper output) { - private readonly ITestOutputHelper output; - public SpinnerViewTests (ITestOutputHelper output) { this.output = output; } - [Theory] [AutoInitShutdown] [InlineData (true)] diff --git a/Tests/UnitTests/Views/StatusBarTests.cs b/Tests/UnitTests/Views/StatusBarTests.cs index 15ad8309bb..73f9f42933 100644 --- a/Tests/UnitTests/Views/StatusBarTests.cs +++ b/Tests/UnitTests/Views/StatusBarTests.cs @@ -16,22 +16,22 @@ public void AddItemAt_RemoveItem_Replacing () sb.AddShortcutAt (2, new (Key.C.WithCtrl, "Close", null)); - Assert.Equal ("Open", sb.Subviews [0].Title); - Assert.Equal ("Save", sb.Subviews [1].Title); - Assert.Equal ("Close", sb.Subviews [2].Title); - Assert.Equal ("Quit", sb.Subviews [^1].Title); + Assert.Equal ("Open", sb.SubViews.ElementAt (0).Title); + Assert.Equal ("Save", sb.SubViews.ElementAt (1).Title); + Assert.Equal ("Close", sb.SubViews.ElementAt (2).Title); + Assert.Equal ("Quit", sb.SubViews.ToArray() [^1].Title); Assert.Equal ("Save", sb.RemoveShortcut (1).Title); - Assert.Equal ("Open", sb.Subviews [0].Title); - Assert.Equal ("Close", sb.Subviews [1].Title); - Assert.Equal ("Quit", sb.Subviews [^1].Title); + Assert.Equal ("Open", sb.SubViews.ElementAt (0).Title); + Assert.Equal ("Close", sb.SubViews.ElementAt (1).Title); + Assert.Equal ("Quit", sb.SubViews.ToArray () [^1].Title); sb.AddShortcutAt (1, new Shortcut (Key.A.WithCtrl, "Save As", null)); - Assert.Equal ("Open", sb.Subviews [0].Title); - Assert.Equal ("Save As", sb.Subviews [1].Title); - Assert.Equal ("Quit", sb.Subviews [^1].Title); + Assert.Equal ("Open", sb.SubViews.ElementAt (0).Title); + Assert.Equal ("Save As", sb.SubViews.ElementAt (1).Title); + Assert.Equal ("Quit", sb.SubViews.ToArray () [^1].Title); } //[Fact] @@ -131,7 +131,7 @@ public void StatusBar_Constructor_Default () { var sb = new StatusBar (); - Assert.Empty (sb.Subviews); + Assert.Empty (sb.SubViews); Assert.True (sb.CanFocus); Assert.Equal (Colors.ColorSchemes ["Menu"], sb.ColorScheme); Assert.Equal (0, sb.X); @@ -174,7 +174,7 @@ public void StatusBar_Constructor_Default () // w.Add (statusBar2); // Assert.Equal (w.StatusBar, statusBar2); - // var menuBars = w.Subviews.OfType ().ToArray (); + // var menuBars = w.SubViews.OfType ().ToArray (); // Assert.Equal (2, menuBars.Length); // Assert.Equal (Dim.Fill (0), menuBars [0].Width); diff --git a/Tests/UnitTests/Views/TabViewTests.cs b/Tests/UnitTests/Views/TabViewTests.cs index 0ec61e4ff1..2860452945 100644 --- a/Tests/UnitTests/Views/TabViewTests.cs +++ b/Tests/UnitTests/Views/TabViewTests.cs @@ -1,6 +1,5 @@ using System.Globalization; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -102,7 +101,7 @@ public void MouseClick_ChangesTab () tv.Draw (); - View tabRow = tv.Subviews [0]; + View tabRow = tv.SubViews.ElementAt (0); Assert.Equal ("TabRow", tabRow.GetType ().Name); DriverAssert.AssertDriverContentsAre ( @@ -185,7 +184,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab () tv.Draw (); - View tabRow = tv.Subviews [0]; + View tabRow = tv.SubViews.ElementAt (0); Assert.Equal ("TabRow", tabRow.GetType ().Name); DriverAssert.AssertDriverContentsAre ( @@ -273,7 +272,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () tv.Draw (); - View tabRow = tv.Subviews [0]; + View tabRow = tv.SubViews.ElementAt (0); Assert.Equal ("TabRow", tabRow.GetType ().Name); DriverAssert.AssertDriverContentsAre ( @@ -416,7 +415,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 () var btnSubView = new View () { Id = "btnSubView", - Title = "_Subview", + Title = "_SubView", CanFocus = true }; tv.SelectedTab.View.Add (btnSubView); @@ -662,7 +661,7 @@ public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames ( ); tv.SelectedTab = tab2; - Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRow")).MostFocused); + Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused); tv.Layout (); View.SetClipToScreen (); @@ -808,7 +807,7 @@ public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames () ); tv.SelectedTab = tab2; - Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRow")).MostFocused); + Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused); tv.Layout (); View.SetClipToScreen (); diff --git a/Tests/UnitTests/Views/TableViewTests.cs b/Tests/UnitTests/Views/TableViewTests.cs index 63dc829dbe..bef6582efd 100644 --- a/Tests/UnitTests/Views/TableViewTests.cs +++ b/Tests/UnitTests/Views/TableViewTests.cs @@ -1,8 +1,6 @@ using System.Collections; using System.Data; using System.Globalization; -using System.Reflection; -using UnitTests; using UnitTests; using Xunit.Abstractions; @@ -441,7 +439,7 @@ public void LongColumnTest () dt.Rows.Add (1, 2, "aaa"); tableView.Table = new DataTableSource (dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); // default behaviour of TableView is not to render @@ -764,7 +762,7 @@ public void ScrollRight_SmoothScrolling () tableView.EndInit (); tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); // 3 columns are visibile tableView.Viewport = new (0, 0, 7, 5); @@ -1042,7 +1040,7 @@ public void TableView_ColorsTest_ColorGetter (bool focused) { TableView tv = SetUpMiniTable (out DataTable dt); - tv.LayoutSubviews (); + tv.LayoutSubViews (); // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); @@ -1142,7 +1140,7 @@ public void TableView_ColorsTest_ColorGetter (bool focused) public void TableView_ColorsTest_RowColorGetter (bool focused) { TableView tv = SetUpMiniTable (out DataTable dt); - tv.LayoutSubviews (); + tv.LayoutSubViews (); // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); @@ -1236,7 +1234,7 @@ public void TableView_ColorsTest_RowColorGetter (bool focused) public void TableView_ColorTests_FocusedOrNot (bool focused) { TableView tv = SetUpMiniTable (); - tv.LayoutSubviews (); + tv.LayoutSubViews (); // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); @@ -1283,7 +1281,7 @@ public void TableView_ColorTests_InvertSelectedCellFirstCharacter (bool focused) { TableView tv = SetUpMiniTable (); tv.Style.InvertSelectedCellFirstCharacter = true; - tv.LayoutSubviews (); + tv.LayoutSubViews (); // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); @@ -1547,7 +1545,7 @@ public void TableViewMultiSelect_CannotFallOffTop () { TableView tv = SetUpMiniTable (out DataTable dt); dt.Rows.Add (1, 2); // add another row (brings us to 2 rows) - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.MultiSelect = true; tv.SelectedColumn = 1; @@ -1580,7 +1578,7 @@ public void Test_CollectionNavigator () new () { { "Name", t => t }, { "EndsWith", t => t.Last () } } ); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.Draw (); @@ -1661,7 +1659,7 @@ public void Test_ScreenToCell () TableView tableView = GetTwoRowSixColumnTable (); tableView.BeginInit (); tableView.EndInit (); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); @@ -1739,7 +1737,7 @@ public void Test_ScreenToCell () public void Test_ScreenToCell_DataColumnOverload () { TableView tableView = GetTwoRowSixColumnTable (); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); @@ -1856,7 +1854,7 @@ public void TestColumnStyle_AllColumnsVisibleFalse_BehavesAsTableNull () tableView.Style.GetOrCreateColumnStyle (i).Visible = false; } - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); // expect nothing to be rendered when all columns are invisible var expected = @@ -1880,7 +1878,7 @@ public void TestColumnStyle_AllColumnsVisibleFalse_BehavesAsTableNull () public void TestColumnStyle_FirstColumnVisibleFalse_CursorStaysAt1 (bool useHome) { TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Style.GetOrCreateColumnStyle (0).Visible = false; tableView.SelectedColumn = 0; @@ -1909,7 +1907,7 @@ public void TestColumnStyle_FirstColumnVisibleFalse_IsNotRendered () tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.GetOrCreateColumnStyle (0).Visible = false; - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); var expected = @@ -1928,7 +1926,7 @@ public void TestColumnStyle_FirstColumnVisibleFalse_IsNotRendered () public void TestColumnStyle_LastColumnVisibleFalse_CursorStaysAt2 (bool useEnd) { TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); // select D tableView.SelectedColumn = 3; @@ -1960,7 +1958,7 @@ public void TestColumnStyle_PreceedingColumnsInvisible_NoScrollIndicator () tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.ColumnOffset = 1; - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); // normally we should have scroll indicators because A,E and F are of screen @@ -2010,7 +2008,7 @@ public void TestColumnStyle_RemainingColumnsInvisible_NoScrollIndicator () tableView.Style.ShowHorizontalScrollIndicators = true; tableView.Style.ShowHorizontalHeaderUnderline = true; - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.SetNeedsDraw (); View.SetClipToScreen (); tableView.Draw (); @@ -2045,7 +2043,7 @@ public void TestColumnStyle_RemainingColumnsInvisible_NoScrollIndicator () public void TestColumnStyle_VisibleFalse_CursorStepsOverInvisibleColumns () { TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Style.GetOrCreateColumnStyle (1).Visible = false; tableView.SelectedColumn = 0; @@ -2073,7 +2071,7 @@ bool invisibleCol ) { TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Style.SmoothHorizontalScrolling = smooth; if (invisibleCol) @@ -2109,7 +2107,7 @@ public void TestColumnStyle_VisibleFalse_IsNotRendered () TableView tableView = GetABCDEFTableView (out _); tableView.Style.GetOrCreateColumnStyle (1).Visible = false; - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.Draw (); var expected = @@ -2125,7 +2123,7 @@ public void TestColumnStyle_VisibleFalse_IsNotRendered () public void TestColumnStyle_VisibleFalse_MultiSelected () { TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); // user has rectangular selection tableView.MultiSelectedRegions.Push ( @@ -2159,7 +2157,7 @@ public void TestColumnStyle_VisibleFalse_MultiSelected () public void TestColumnStyle_VisibleFalse_MultiSelectingStepsOverInvisibleColumns () { TableView tableView = GetABCDEFTableView (out _); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); // if middle column is invisible tableView.Style.GetOrCreateColumnStyle (1).Visible = false; @@ -2182,7 +2180,7 @@ public void TestControlClick_MultiSelect_ThreeRowTable_FullRowSelect () { TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.MultiSelect = true; @@ -2228,7 +2226,7 @@ public void TestEnumerableDataSource_BasicTypes () } ); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.Draw (); @@ -2253,7 +2251,7 @@ public void TestFullRowSelect_AlwaysUseNormalColorForVerticalCellLines () tv.Viewport = new (0, 0, 7, 6); tv.Frame = new (0, 0, 7, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.FullRowSelect = true; tv.Style.ShowHorizontalBottomline = true; @@ -2306,7 +2304,7 @@ public void TestFullRowSelect_SelectionColorDoesNotStop_WhenShowVerticalCellLine { TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.Viewport = new (0, 0, 7, 6); @@ -2362,7 +2360,7 @@ public void TestFullRowSelect_SelectionColorStopsAtTableEdge_WithCellLines () tv.Viewport = new (0, 0, 7, 6); tv.Frame = new (0, 0, 7, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.FullRowSelect = true; tv.Style.ShowHorizontalBottomline = true; @@ -2433,7 +2431,7 @@ public void TestListTableSource (Orientation orient, bool parallel) tv.Table = new ListTableSource (list, tv, listStyle); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.Draw (); @@ -2500,7 +2498,7 @@ public void TestListTableSource (Orientation orient, bool parallel) public void TestMoveStartEnd_WithFullRowSelect (bool withFullRowSelect) { TableView tableView = GetTwoRowSixColumnTable (); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); tableView.FullRowSelect = withFullRowSelect; tableView.SelectedRow = 1; @@ -2544,7 +2542,7 @@ public void TestMoveStartEnd_WithFullRowSelect (bool withFullRowSelect) public void TestShiftClick_MultiSelect_TwoRowTable_FullRowSelect () { TableView tv = GetTwoRowSixColumnTable (); - tv.LayoutSubviews (); + tv.LayoutSubViews (); tv.MultiSelect = true; @@ -2578,7 +2576,7 @@ public void TestTableViewCheckboxes_ByObject () ConfigurationManager.Reset(); TableView tv = GetPetTable (out EnumerableTableSource source); - tv.LayoutSubviews (); + tv.LayoutSubViews (); IReadOnlyCollection pets = source.Data; CheckBoxTableSourceWrapperByObject wrapper = new ( @@ -2672,7 +2670,7 @@ public void TestTableViewCheckboxes_MultiSelectIsUnion_WhenToggling () { TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); var wrapper = new CheckBoxTableSourceWrapperByIndex (tv, tv.Table); tv.Table = wrapper; @@ -2739,7 +2737,7 @@ public void TestTableViewCheckboxes_SelectAllToggle () { TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); var wrapper = new CheckBoxTableSourceWrapperByIndex (tv, tv.Table); tv.Table = wrapper; @@ -2789,7 +2787,7 @@ public void TestTableViewCheckboxes_SelectAllToggle () public void TestTableViewCheckboxes_SelectAllToggle_ByObject () { TableView tv = GetPetTable (out EnumerableTableSource source); - tv.LayoutSubviews (); + tv.LayoutSubViews (); IReadOnlyCollection pets = source.Data; CheckBoxTableSourceWrapperByObject wrapper = new ( @@ -2851,7 +2849,7 @@ public void TestTableViewCheckboxes_Simple () { TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.LayoutSubviews (); + tv.LayoutSubViews (); var wrapper = new CheckBoxTableSourceWrapperByIndex (tv, tv.Table); tv.Table = wrapper; @@ -2934,7 +2932,7 @@ public void TestTableViewCheckboxes_Simple () public void TestTableViewRadioBoxes_Simple_ByObject () { TableView tv = GetPetTable (out EnumerableTableSource source); - tv.LayoutSubviews (); + tv.LayoutSubViews (); IReadOnlyCollection pets = source.Data; CheckBoxTableSourceWrapperByObject wrapper = new ( @@ -3032,7 +3030,7 @@ public void TestToggleCells_MultiSelectOn () { // 2 row table TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.MultiSelect = true; @@ -3104,7 +3102,7 @@ public void TestToggleCells_MultiSelectOn_FullRowSelect () { // 2 row table TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.FullRowSelect = true; tableView.MultiSelect = true; @@ -3142,7 +3140,7 @@ public void TestToggleCells_MultiSelectOn_SquareSelectToggled () { // 3 row table TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); dt.Rows.Add (1, 2, 3, 4, 5, 6); dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.MultiSelect = true; @@ -3180,7 +3178,7 @@ public void TestToggleCells_MultiSelectOn_Two_SquareSelects_BothToggled () { // 6 row table TableView tableView = GetABCDEFTableView (out DataTable dt); - tableView.LayoutSubviews (); + tableView.LayoutSubViews (); dt.Rows.Add (1, 2, 3, 4, 5, 6); dt.Rows.Add (1, 2, 3, 4, 5, 6); dt.Rows.Add (1, 2, 3, 4, 5, 6); @@ -3471,7 +3469,7 @@ private TableView GetPetTable (out EnumerableTableSource source) } ); - tv.LayoutSubviews (); + tv.LayoutSubViews (); return tv; } diff --git a/Tests/UnitTests/Views/TextFieldTests.cs b/Tests/UnitTests/Views/TextFieldTests.cs index a80e679618..14c84a282f 100644 --- a/Tests/UnitTests/Views/TextFieldTests.cs +++ b/Tests/UnitTests/Views/TextFieldTests.cs @@ -2,7 +2,6 @@ using System.Reflection; using System.Text; using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -354,7 +353,7 @@ public void Copy_Paste_Surrogate_Pairs () Assert.Equal ( "TextField with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", - Application.Driver?.Clipboard.GetClipboardData () + Application.Driver?.Clipboard!.GetClipboardData () ); Assert.Equal (string.Empty, _textField.Text); _textField.Paste (); @@ -368,9 +367,9 @@ public void Copy_Paste_Text_Changing_Updates_Cursor_Position () _textField.BeginInit (); _textField.EndInit (); - _textField.TextChanging += _textField_TextChanging; + _textField.TextChanging += TextFieldTextChanging; - void _textField_TextChanging (object sender, CancelEventArgs e) + void TextFieldTextChanging (object sender, CancelEventArgs e) { if (e.NewValue.GetRuneCount () > 11) { @@ -381,14 +380,14 @@ void _textField_TextChanging (object sender, CancelEventArgs e) Assert.Equal (32, _textField.CursorPosition); _textField.SelectAll (); _textField.Cut (); - Assert.Equal ("TAB to jump between text fields.", Application.Driver?.Clipboard.GetClipboardData ()); + Assert.Equal ("TAB to jump between text fields.", Application.Driver?.Clipboard!.GetClipboardData ()); Assert.Equal (string.Empty, _textField.Text); Assert.Equal (0, _textField.CursorPosition); _textField.Paste (); Assert.Equal ("TAB to jump", _textField.Text); Assert.Equal (11, _textField.CursorPosition); - _textField.TextChanging -= _textField_TextChanging; + _textField.TextChanging -= TextFieldTextChanging; } [Fact] @@ -2068,12 +2067,12 @@ public void Autocomplete_Popup_Added_To_SuperView_On_Init () TextField t = new (); superView.Add (t); - Assert.Single (superView.Subviews); + Assert.Single (superView.SubViews); superView.BeginInit (); superView.EndInit (); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); } [Fact] @@ -2087,7 +2086,7 @@ public void Autocomplete__Added_To_SuperView_On_Add () superView.BeginInit (); superView.EndInit (); - Assert.Empty (superView.Subviews); + Assert.Empty (superView.SubViews); TextField t = new () { @@ -2096,7 +2095,7 @@ public void Autocomplete__Added_To_SuperView_On_Add () superView.Add (t); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); } [Fact] @@ -2160,7 +2159,7 @@ public void Autocomplete_Visible_False_By_Default () superView.BeginInit (); superView.EndInit (); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); Assert.True (t.Visible); Assert.False (t.Autocomplete.Visible); diff --git a/Tests/UnitTests/Views/TextViewTests.cs b/Tests/UnitTests/Views/TextViewTests.cs index aed7bd09eb..6a71e63b12 100644 --- a/Tests/UnitTests/Views/TextViewTests.cs +++ b/Tests/UnitTests/Views/TextViewTests.cs @@ -1,9 +1,8 @@ using System.Reflection; using System.Text; using System.Text.RegularExpressions; -using Xunit.Abstractions; -using UnitTests; using UnitTests; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -80,7 +79,7 @@ public void BackTab_Test_Follow_By_Tab () int tabWidth = _textView.TabWidth; int leftCol = _textView.LeftColumn; _textView.MoveEnd (); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -88,7 +87,7 @@ public void BackTab_Test_Follow_By_Tab () { col--; _textView.NewKeyDownEvent (Key.Tab.WithShift); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -97,7 +96,7 @@ public void BackTab_Test_Follow_By_Tab () { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -131,7 +130,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () Assert.False (fv.CanFocus); Assert.False (fv.HasFocus); - tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new() { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Empty (tv.SelectedText); Assert.False (tv.CanFocus); @@ -141,7 +140,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () fv.CanFocus = true; tv.CanFocus = true; - tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new() { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Equal ("some ", tv.SelectedText); Assert.True (tv.CanFocus); @@ -150,7 +149,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () Assert.True (fv.HasFocus); fv.CanFocus = false; - tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new() { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText Assert.True (tv.CanFocus); // v2: CanFocus is not longer automatically changed @@ -170,7 +169,7 @@ public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_Selec Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal (2, _textView.SelectedLength); Assert.Equal ("TA", _textView.SelectedText); - _textView.CursorPosition = new Point (20, 0); + _textView.CursorPosition = new (20, 0); Assert.Equal (2, _textView.SelectionStartColumn); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (18, _textView.SelectedLength); @@ -345,7 +344,6 @@ public void ContentsChanged_Event_Fires_On_Set_Text () tv.Text = "defg"; Assert.Equal (2, eventcount); // for set Text = "defg" top.Dispose (); - } [Fact] @@ -381,7 +379,6 @@ public void ContentsChanged_Event_Fires_On_Typing () Assert.Equal (3, eventcount); Assert.Equal ("Yay", tv.Text); top.Dispose (); - } [Fact] @@ -533,23 +530,23 @@ public void Copy_Or_Cut_And_Paste_With_No_Selection () { _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); + _textView.CursorPosition = new (24, 0); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); Assert.Equal ("TAB to jump between text fields.", _textView.Text); _textView.SelectionStartColumn = 0; _textView.SelectionStartRow = 0; - Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.Equal (new (24, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); _textView.IsSelecting = false; _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.Equal (new (28, 0), _textView.CursorPosition); Assert.False (_textView.IsSelecting); Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); _textView.SelectionStartColumn = 24; _textView.SelectionStartRow = 0; _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut - Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.Equal (new (24, 0), _textView.CursorPosition); Assert.False (_textView.IsSelecting); Assert.Equal ("", _textView.SelectedText); Assert.Equal ("TAB to jump between text fields.", _textView.Text); @@ -557,7 +554,7 @@ public void Copy_Or_Cut_And_Paste_With_No_Selection () _textView.SelectionStartRow = 0; _textView.IsSelecting = false; _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.Equal (new (28, 0), _textView.CursorPosition); Assert.False (_textView.IsSelecting); Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); } @@ -568,7 +565,7 @@ public void Copy_Or_Cut_And_Paste_With_Selection () { _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); + _textView.CursorPosition = new (24, 0); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); Assert.Equal ("TAB to jump between text fields.", _textView.Text); @@ -587,7 +584,7 @@ public void Copy_Or_Cut_Not_Null_If_Has_Selection () { _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); + _textView.CursorPosition = new (24, 0); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut @@ -628,7 +625,7 @@ public void Copy_Paste_Surrogate_Pairs () public void Copy_Without_Selection () { _textView.Text = "This is the first line.\nThis is the second line.\n"; - _textView.CursorPosition = new Point (0, _textView.Lines - 1); + _textView.CursorPosition = new (0, _textView.Lines - 1); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste @@ -636,7 +633,7 @@ public void Copy_Without_Selection () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text ); - _textView.CursorPosition = new Point (3, 1); + _textView.CursorPosition = new (3, 1); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste @@ -644,14 +641,14 @@ public void Copy_Without_Selection () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text ); - Assert.Equal (new Point (3, 2), _textView.CursorPosition); + Assert.Equal (new (3, 2), _textView.CursorPosition); _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ( $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text ); - Assert.Equal (new Point (3, 3), _textView.CursorPosition); + Assert.Equal (new (3, 3), _textView.CursorPosition); } [Fact] @@ -672,7 +669,7 @@ public void Cursor_Position_Multiline_False_Initialization () [TextViewTestsAutoInitShutdown] public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length () { - _textView.CursorPosition = new Point (33, 1); + _textView.CursorPosition = new (33, 1); Assert.Equal (32, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal (0, _textView.SelectedLength); @@ -683,7 +680,7 @@ public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_L [TextViewTestsAutoInitShutdown] public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero () { - _textView.CursorPosition = new Point (-1, -1); + _textView.CursorPosition = new (-1, -1); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal (0, _textView.SelectedLength); @@ -697,7 +694,7 @@ public void Cut_Not_Allowed_If_ReadOnly_Is_True () _textView.ReadOnly = true; _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); + _textView.CursorPosition = new (24, 0); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); @@ -730,51 +727,51 @@ public void DeleteTextBackwards_WordWrap_False_Return_Undo () Assert.Equal (Point.Empty, tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (3, 0); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + tv.CursorPosition = new (3, 0); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.RunIteration (ref rs); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (0, 1); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + tv.CursorPosition = new (0, 1); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.RunIteration (ref rs); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + Assert.Equal (new (22, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line.This is the second line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Application.RunIteration (ref rs); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); while (tv.Text != envText) { @@ -783,7 +780,7 @@ This is the second line. Application.RunIteration (ref rs); Assert.Equal (envText, tv.Text); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.False (tv.IsDirty); top.Dispose (); } @@ -804,60 +801,61 @@ public void DeleteTextBackwards_WordWrap_True_Return_Undo () Assert.Equal (Point.Empty, tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (3, 0); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + tv.CursorPosition = new (3, 0); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.RunIteration (ref rs); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (0, 1); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + tv.CursorPosition = new (0, 1); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.RunIteration (ref rs); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + Assert.Equal (new (22, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line.This is the second line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Application.RunIteration (ref rs); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); while (tv.Text != envText) { Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } + Application.RunIteration (ref rs); Assert.Equal (envText, tv.Text); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.False (tv.IsDirty); top.Dispose (); } @@ -878,51 +876,51 @@ public void DeleteTextForwards_WordWrap_False_Return_Undo () Assert.Equal (Point.Empty, tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (2, 0); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + tv.CursorPosition = new (2, 0); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete)); Application.RunIteration (ref rs); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (22, 0); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + tv.CursorPosition = new (22, 0); + Assert.Equal (new (22, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete)); Application.RunIteration (ref rs); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + Assert.Equal (new (22, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line.This is the second line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Application.RunIteration (ref rs); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); while (tv.Text != envText) { @@ -930,7 +928,7 @@ This is the second line. } Assert.Equal (envText, tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.False (tv.IsDirty); top.Dispose (); } @@ -951,51 +949,51 @@ public void DeleteTextForwards_WordWrap_True_Return_Undo () Assert.Equal (Point.Empty, tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (2, 0); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + tv.CursorPosition = new (2, 0); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete)); Application.RunIteration (ref rs); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); - tv.CursorPosition = new Point (22, 0); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + tv.CursorPosition = new (22, 0); + Assert.Equal (new (22, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete)); Application.RunIteration (ref rs); - Assert.Equal (new Point (22, 0), tv.CursorPosition); + Assert.Equal (new (22, 0), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line.This is the second line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Application.RunIteration (ref rs); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Ths is the first line. This is the second line. ", - _output - ); + _output + ); while (tv.Text != envText) { @@ -1005,7 +1003,7 @@ This is the second line. Application.RunIteration (ref rs); Assert.Equal (envText, tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.False (tv.IsDirty); top.Dispose (); } @@ -1034,7 +1032,7 @@ public void DesiredCursorVisibility_Horizontal_Navigation () for (var i = 0; i < 12; i++) { - tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledRight }); + tv.NewMouseEvent (new() { Flags = MouseFlags.WheeledRight }); Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn); Application.PositionCursor (); Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility); @@ -1043,7 +1041,7 @@ public void DesiredCursorVisibility_Horizontal_Navigation () for (var i = 11; i > 0; i--) { - tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledLeft }); + tv.NewMouseEvent (new() { Flags = MouseFlags.WheeledLeft }); Assert.Equal (i - 1, tv.LeftColumn); Application.PositionCursor (); @@ -1086,7 +1084,7 @@ public void DesiredCursorVisibility_Vertical_Navigation () for (var i = 0; i < 12; i++) { - tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledDown }); + tv.NewMouseEvent (new() { Flags = MouseFlags.WheeledDown }); Application.PositionCursor (); Assert.Equal (i + 1, tv.TopRow); Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility); @@ -1095,7 +1093,7 @@ public void DesiredCursorVisibility_Vertical_Navigation () for (var i = 12; i > 0; i--) { - tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledUp }); + tv.NewMouseEvent (new() { Flags = MouseFlags.WheeledUp }); Application.PositionCursor (); Assert.Equal (i - 1, tv.TopRow); @@ -1142,7 +1140,7 @@ public void HistoryText_ClearHistoryChanges () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -1153,7 +1151,7 @@ public void HistoryText_ClearHistoryChanges () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); } @@ -1169,7 +1167,7 @@ public void HistoryText_Exceptions () { Assert.Throws ( () => ht.Add ( - new List> { new () }, + new() { new () }, Point.Empty, (HistoryText.LineStatus)ls ) @@ -1177,7 +1175,7 @@ public void HistoryText_Exceptions () } } - Assert.Null (Record.Exception (() => ht.Add (new List> { new () }, Point.Empty))); + Assert.Null (Record.Exception (() => ht.Add (new() { new () }, Point.Empty))); } [Fact] @@ -1194,35 +1192,35 @@ public void HistoryText_IsDirty_HasHistoryChanges () Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"1{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"1{Environment.NewLine}2", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ($"1{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -1247,34 +1245,34 @@ public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards () Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ("12", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.D3)); Assert.Equal ("123", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("12", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.D4)); Assert.Equal ("124", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("124", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); } [Fact] @@ -1284,7 +1282,7 @@ public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste () var text = "This is the first line.\nThis is the second line.\nThis is the third line."; var tv = new TextView { Text = text }; - tv.CursorPosition = new Point (23, 0); + tv.CursorPosition = new (23, 0); Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); @@ -1295,7 +1293,7 @@ public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste () Assert.Equal ("", tv.SelectedText); Assert.Equal ("This is the first line.", Clipboard.Contents); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 0), tv.CursorPosition); + Assert.Equal (new (23, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); @@ -1304,7 +1302,7 @@ public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (23, 1), tv.CursorPosition); + Assert.Equal (new (23, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1314,7 +1312,7 @@ public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 0), tv.CursorPosition); + Assert.Equal (new (23, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1324,7 +1322,7 @@ public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (23, 1), tv.CursorPosition); + Assert.Equal (new (23, 1), tv.CursorPosition); } [Fact] @@ -1335,7 +1333,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.CursorPosition = new (17, 0); Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); @@ -1345,11 +1343,11 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () ); Assert.Equal ("", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); tv.SelectionStartColumn = 12; tv.SelectionStartRow = 1; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); @@ -1358,7 +1356,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 1), tv.CursorPosition); + Assert.Equal (new (17, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1368,7 +1366,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 1), tv.CursorPosition); + Assert.Equal (new (12, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1377,7 +1375,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1387,7 +1385,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1396,7 +1394,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 1), tv.CursorPosition); + Assert.Equal (new (17, 1), tv.CursorPosition); } [Fact] @@ -1407,7 +1405,7 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.CursorPosition = new (17, 0); Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); @@ -1417,15 +1415,15 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste () ); Assert.Equal ("", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.CursorPosition = new (11, 1); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1435,13 +1433,13 @@ public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); } [Fact] @@ -1452,13 +1450,13 @@ public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); tv.IsSelecting = false; @@ -1469,13 +1467,13 @@ public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1485,7 +1483,7 @@ public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); } [Fact] @@ -1498,28 +1496,28 @@ public void HistoryText_Undo_Redo_Disabled_On_WordWrap () tv.WordWrap = true; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (12, 2); + tv.CursorPosition = new (12, 2); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); } [Fact] @@ -1546,7 +1544,7 @@ public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Select tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1566,7 +1564,7 @@ public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Select tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); } [Fact] @@ -1576,23 +1574,23 @@ public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (12, 2); + tv.CursorPosition = new (12, 2); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1602,25 +1600,25 @@ public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (new (12, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1630,19 +1628,19 @@ public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (new (12, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); } [Fact] @@ -1652,7 +1650,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.CursorPosition = new (17, 0); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -1661,7 +1659,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.A)); @@ -1670,7 +1668,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1680,7 +1678,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1690,7 +1688,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -1701,7 +1699,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1710,7 +1708,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1720,7 +1718,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -1730,7 +1728,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -1741,7 +1739,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1750,7 +1748,7 @@ public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); } [Fact] @@ -1825,21 +1823,21 @@ public void HistoryText_Undo_Redo_KillToLeftStart () Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 1), tv.CursorPosition); + Assert.Equal (new (12, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ("Second line.", Clipboard.Contents); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift)); Assert.Equal ("First line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift)); Assert.Equal ("", tv.Text); @@ -1852,28 +1850,28 @@ public void HistoryText_Undo_Redo_KillToLeftStart () Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 1), tv.CursorPosition); + Assert.Equal (new (12, 1), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); @@ -1891,43 +1889,43 @@ public void HistoryText_Undo_Redo_KillWordBackward () Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 1), tv.CursorPosition); + Assert.Equal (new (12, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (11, 1), tv.CursorPosition); + Assert.Equal (new (11, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("", tv.Text); @@ -1939,68 +1937,68 @@ public void HistoryText_Undo_Redo_KillWordBackward () Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (11, 1), tv.CursorPosition); + Assert.Equal (new (11, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (12, 1), tv.CursorPosition); + Assert.Equal (new (12, 1), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (11, 1), tv.CursorPosition); + Assert.Equal (new (11, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); @@ -2111,7 +2109,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); for (var i = 0; i < ntimes; i++) { @@ -2123,9 +2121,9 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 1), tv.CursorPosition); + Assert.Equal (new (4, 1), tv.CursorPosition); - tv.CursorPosition = new Point (7, 0); + tv.CursorPosition = new (7, 0); for (var i = 0; i < ntimes; i++) { @@ -2137,9 +2135,9 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 0), tv.CursorPosition); + Assert.Equal (new (4, 0), tv.CursorPosition); - tv.CursorPosition = new Point (7, 2); + tv.CursorPosition = new (7, 2); for (var i = 0; i < ntimes; i++) { @@ -2151,7 +2149,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2164,7 +2162,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text ); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); break; case 1: @@ -2172,7 +2170,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text ); - Assert.Equal (new Point (6, 2), tv.CursorPosition); + Assert.Equal (new (6, 2), tv.CursorPosition); break; case 2: @@ -2180,7 +2178,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); break; } @@ -2191,7 +2189,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2204,7 +2202,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (5, 0), tv.CursorPosition); + Assert.Equal (new (5, 0), tv.CursorPosition); break; case 1: @@ -2212,7 +2210,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); break; case 2: @@ -2220,7 +2218,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); break; } @@ -2231,7 +2229,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2244,7 +2242,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (5, 1), tv.CursorPosition); + Assert.Equal (new (5, 1), tv.CursorPosition); break; case 1: @@ -2252,7 +2250,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (6, 1), tv.CursorPosition); + Assert.Equal (new (6, 1), tv.CursorPosition); break; case 2: @@ -2260,7 +2258,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); break; } @@ -2271,7 +2269,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2283,7 +2281,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 1), tv.CursorPosition); + Assert.Equal (new (4, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2295,7 +2293,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 0), tv.CursorPosition); + Assert.Equal (new (4, 0), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2307,7 +2305,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); top.Dispose (); } @@ -2329,7 +2327,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); for (var i = 0; i < ntimes; i++) { @@ -2341,9 +2339,9 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); - tv.CursorPosition = new Point (7, 0); + tv.CursorPosition = new (7, 0); for (var i = 0; i < ntimes; i++) { @@ -2355,9 +2353,9 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); - tv.CursorPosition = new Point (7, 2); + tv.CursorPosition = new (7, 2); for (var i = 0; i < ntimes; i++) { @@ -2369,7 +2367,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2381,7 +2379,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2393,7 +2391,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2405,7 +2403,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2417,7 +2415,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2429,7 +2427,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -2441,7 +2439,7 @@ public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); top.Dispose (); } @@ -2463,7 +2461,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () Assert.Equal (Point.Empty, tv.CursorPosition); var messy = " messy"; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); tv.InsertText (messy); Assert.Equal ( @@ -2471,9 +2469,9 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); - tv.CursorPosition = new Point (7, 0); + tv.CursorPosition = new (7, 0); tv.InsertText (messy); Assert.Equal ( @@ -2481,9 +2479,9 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); - tv.CursorPosition = new Point (7, 2); + tv.CursorPosition = new (7, 2); tv.InsertText (messy); Assert.Equal ( @@ -2491,7 +2489,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 2), tv.CursorPosition); + Assert.Equal (new (13, 2), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2503,7 +2501,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 2), tv.CursorPosition); + Assert.Equal (new (7, 2), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2515,7 +2513,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2527,7 +2525,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2539,7 +2537,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2551,7 +2549,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -2563,7 +2561,7 @@ public void HistoryText_Undo_Redo_Multi_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 2), tv.CursorPosition); + Assert.Equal (new (13, 2), tv.CursorPosition); top.Dispose (); } @@ -2580,23 +2578,23 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2606,25 +2604,25 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2634,19 +2632,19 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); } [Fact] @@ -2657,7 +2655,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); @@ -2667,10 +2665,10 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting ); Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); tv.IsSelecting = false; - tv.CursorPosition = new Point (17, 1); + tv.CursorPosition = new (17, 1); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); @@ -2679,7 +2677,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2689,7 +2687,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 1), tv.CursorPosition); + Assert.Equal (new (17, 1), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -2699,7 +2697,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); } [Fact] @@ -2710,7 +2708,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); @@ -2720,7 +2718,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting ); Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); tv.IsSelecting = false; @@ -2731,7 +2729,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2741,7 +2739,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -2751,7 +2749,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); } [Fact] @@ -2781,7 +2779,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All () tv.SelectedText ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); @@ -2804,7 +2802,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All () ); Assert.Equal ("", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -2847,7 +2845,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All () tv.SelectedText ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); @@ -2870,7 +2868,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All () ); Assert.Equal ("", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -2905,7 +2903,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () Assert.Equal (Point.Empty, tv.CursorPosition); var messy = " messy"; - tv.CursorPosition = new Point (7, 0); + tv.CursorPosition = new (7, 0); tv.SelectionStartColumn = 11; tv.SelectionStartRow = 2; Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength); @@ -2918,32 +2916,32 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () { case 0: Assert.Equal ("This is third line.", tv.Text); - Assert.Equal (new Point (8, 0), tv.CursorPosition); + Assert.Equal (new (8, 0), tv.CursorPosition); break; case 1: Assert.Equal ("This is m third line.", tv.Text); - Assert.Equal (new Point (9, 0), tv.CursorPosition); + Assert.Equal (new (9, 0), tv.CursorPosition); break; case 2: Assert.Equal ("This is me third line.", tv.Text); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); break; case 3: Assert.Equal ("This is mes third line.", tv.Text); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); break; case 4: Assert.Equal ("This is mess third line.", tv.Text); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); break; case 5: Assert.Equal ("This is messy third line.", tv.Text); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); break; } @@ -2951,7 +2949,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () Assert.Equal ("This is messy third line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (2, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -2964,27 +2962,27 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () { case 0: Assert.Equal ("This is mess third line.", tv.Text); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); break; case 1: Assert.Equal ("This is mes third line.", tv.Text); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); break; case 2: Assert.Equal ("This is me third line.", tv.Text); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); break; case 3: Assert.Equal ("This is m third line.", tv.Text); - Assert.Equal (new Point (9, 0), tv.CursorPosition); + Assert.Equal (new (9, 0), tv.CursorPosition); break; case 4: Assert.Equal ("This is third line.", tv.Text); - Assert.Equal (new Point (8, 0), tv.CursorPosition); + Assert.Equal (new (8, 0), tv.CursorPosition); break; case 5: @@ -2992,7 +2990,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); break; } @@ -3003,7 +3001,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (2, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -3016,32 +3014,32 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () { case 0: Assert.Equal ("This is third line.", tv.Text); - Assert.Equal (new Point (8, 0), tv.CursorPosition); + Assert.Equal (new (8, 0), tv.CursorPosition); break; case 1: Assert.Equal ("This is m third line.", tv.Text); - Assert.Equal (new Point (9, 0), tv.CursorPosition); + Assert.Equal (new (9, 0), tv.CursorPosition); break; case 2: Assert.Equal ("This is me third line.", tv.Text); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + Assert.Equal (new (10, 0), tv.CursorPosition); break; case 3: Assert.Equal ("This is mes third line.", tv.Text); - Assert.Equal (new Point (11, 0), tv.CursorPosition); + Assert.Equal (new (11, 0), tv.CursorPosition); break; case 4: Assert.Equal ("This is mess third line.", tv.Text); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); break; case 5: Assert.Equal ("This is messy third line.", tv.Text); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); break; } @@ -3049,7 +3047,7 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText () Assert.Equal ("This is messy third line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (13, 0), tv.CursorPosition); + Assert.Equal (new (13, 0), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (2, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -3073,48 +3071,48 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_L tv.SelectionStartColumn = 0; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (0, 1); + tv.CursorPosition = new (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); tv.SelectionStartColumn = 1; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (1, 1); + tv.CursorPosition = new (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ("12hree", tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("12hree", tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); top.Dispose (); @@ -3137,48 +3135,48 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_L tv.SelectionStartColumn = 0; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (0, 1); + tv.CursorPosition = new (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); tv.SelectionStartColumn = 1; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (1, 1); + tv.CursorPosition = new (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); top.Dispose (); @@ -3201,108 +3199,108 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text () Assert.True (tv.NewKeyDownEvent (Key.O.WithShift)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.N)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.W)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.O)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.H)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 3), tv.CursorPosition); + Assert.Equal (new (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); tv.SelectionStartColumn = 0; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (0, 1); + tv.CursorPosition = new (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); tv.SelectionStartColumn = 1; tv.SelectionStartRow = 0; - tv.CursorPosition = new Point (1, 1); + tv.CursorPosition = new (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); @@ -3310,104 +3308,104 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text () Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); @@ -3429,112 +3427,112 @@ public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text () Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 3), tv.CursorPosition); + Assert.Equal (new (0, 3), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); top.Dispose (); @@ -3557,164 +3555,164 @@ public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text () Assert.True (tv.NewKeyDownEvent (Key.O.WithShift)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.N)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.W)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.O)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.H)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 3), tv.CursorPosition); + Assert.Equal (new (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); // Undoing Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -3733,91 +3731,91 @@ public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text () Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (2, 0), tv.CursorPosition); + Assert.Equal (new (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (3, 0), tv.CursorPosition); + Assert.Equal (new (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (1, 1), tv.CursorPosition); + Assert.Equal (new (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (2, 1), tv.CursorPosition); + Assert.Equal (new (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (3, 1), tv.CursorPosition); + Assert.Equal (new (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (2, 2), tv.CursorPosition); + Assert.Equal (new (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (3, 2), tv.CursorPosition); + Assert.Equal (new (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 2), tv.CursorPosition); + Assert.Equal (new (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 2), tv.CursorPosition); + Assert.Equal (new (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 3), tv.CursorPosition); + Assert.Equal (new (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 3), tv.CursorPosition); + Assert.Equal (new (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); top.Dispose (); } @@ -3829,41 +3827,41 @@ public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab () var tv = new TextView { Width = 80, Height = 5, Text = text }; tv.SelectionStartColumn = 6; - tv.CursorPosition = new Point (6, 2); + tv.CursorPosition = new (6, 2); Assert.True (tv.NewKeyDownEvent (Key.Tab)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (6, 2), tv.CursorPosition); + Assert.Equal (new (6, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (7, 0), tv.CursorPosition); + Assert.Equal (new (7, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (6, 0), tv.CursorPosition); + Assert.Equal (new (6, 0), tv.CursorPosition); } [Fact] @@ -3879,7 +3877,7 @@ public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); @@ -3894,7 +3892,7 @@ public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -3911,7 +3909,7 @@ public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); @@ -3940,7 +3938,7 @@ public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -3956,7 +3954,7 @@ public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); } [Fact] @@ -3967,7 +3965,7 @@ public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.CursorPosition = new (17, 0); Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); @@ -3977,15 +3975,15 @@ public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste () ); Assert.Equal ("first", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.CursorPosition = new (11, 1); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -3995,13 +3993,13 @@ public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); } [Fact] @@ -4022,7 +4020,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); for (var i = 0; i < ntimes; i++) { @@ -4034,7 +4032,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 1), tv.CursorPosition); + Assert.Equal (new (4, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -4046,7 +4044,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -4058,7 +4056,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (4, 1), tv.CursorPosition); + Assert.Equal (new (4, 1), tv.CursorPosition); top.Dispose (); } @@ -4080,7 +4078,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); for (var i = 0; i < ntimes; i++) { @@ -4092,7 +4090,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -4104,7 +4102,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < ntimes; i++) { @@ -4116,7 +4114,7 @@ public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); top.Dispose (); } @@ -4138,7 +4136,7 @@ public void HistoryText_Undo_Redo_Single_Line_InsertText () Assert.Equal (Point.Empty, tv.CursorPosition); var messy = " messy"; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); tv.InsertText (messy); Assert.Equal ( @@ -4146,7 +4144,7 @@ public void HistoryText_Undo_Redo_Single_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -4158,7 +4156,7 @@ public void HistoryText_Undo_Redo_Single_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); for (var i = 0; i < messy.Length; i++) { @@ -4170,7 +4168,7 @@ public void HistoryText_Undo_Redo_Single_Line_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); top.Dispose (); } @@ -4192,7 +4190,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); tv.SelectionStartColumn = 11; tv.SelectionStartRow = 1; Assert.Equal (4, tv.SelectedLength); @@ -4207,7 +4205,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 1), tv.CursorPosition); + Assert.Equal (new (5, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4222,7 +4220,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4237,7 +4235,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (5, 1), tv.CursorPosition); + Assert.Equal (new (5, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4262,7 +4260,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight () Assert.Equal (Point.Empty, tv.CursorPosition); var ntimes = 3; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); tv.SelectionStartColumn = 11; tv.SelectionStartRow = 1; Assert.Equal (4, tv.SelectedLength); @@ -4277,7 +4275,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4292,7 +4290,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4307,7 +4305,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4332,7 +4330,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText () Assert.Equal (Point.Empty, tv.CursorPosition); var messy = " messy"; - tv.CursorPosition = new Point (7, 1); + tv.CursorPosition = new (7, 1); tv.SelectionStartColumn = 11; tv.SelectionStartRow = 1; Assert.Equal (4, tv.SelectedLength); @@ -4343,7 +4341,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4358,7 +4356,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (7, 1), tv.CursorPosition); + Assert.Equal (new (7, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4373,7 +4371,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (13, 1), tv.CursorPosition); + Assert.Equal (new (13, 1), tv.CursorPosition); Assert.Equal (11, tv.SelectionStartColumn); Assert.Equal (1, tv.SelectionStartRow); Assert.Equal (0, tv.SelectedLength); @@ -4387,7 +4385,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.CursorPosition = new (17, 0); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -4396,7 +4394,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4406,7 +4404,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4417,7 +4415,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4427,7 +4425,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.Equal (new (17, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4438,7 +4436,7 @@ public void HistoryText_Undo_Redo_Single_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); } [Fact] @@ -4449,7 +4447,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.SelectionStartColumn = 12; tv.SelectionStartRow = 1; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -4458,7 +4456,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4468,7 +4466,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4479,7 +4477,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4489,7 +4487,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4500,7 +4498,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return () tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); } [Fact] @@ -4511,7 +4509,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.SelectionStartColumn = 12; tv.SelectionStartRow = 1; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -4520,7 +4518,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.A)); @@ -4529,7 +4527,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4539,7 +4537,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4549,7 +4547,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4560,7 +4558,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -4569,7 +4567,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4579,7 +4577,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4589,7 +4587,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4600,7 +4598,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (0, 2), tv.CursorPosition); + Assert.Equal (new (0, 2), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -4609,7 +4607,7 @@ public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertT tv.Text ); Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (1, 2), tv.CursorPosition); + Assert.Equal (new (1, 2), tv.CursorPosition); } [Fact] @@ -4619,12 +4617,12 @@ public void HistoryText_Undo_Redo_Three_Line_Selected_Return () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 2); + tv.CursorPosition = new (17, 2); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4634,14 +4632,14 @@ public void HistoryText_Undo_Redo_Three_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 2), tv.CursorPosition); + Assert.Equal (new (17, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4651,14 +4649,14 @@ public void HistoryText_Undo_Redo_Three_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 2), tv.CursorPosition); + Assert.Equal (new (17, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); } [Fact] @@ -4668,7 +4666,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -4677,7 +4675,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4687,7 +4685,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4698,7 +4696,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4708,7 +4706,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4719,7 +4717,7 @@ public void HistoryText_Undo_Redo_Two_Line_Selected_Return () tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); } [Fact] @@ -4729,7 +4727,7 @@ public void HistoryText_Undo_Redo_ApplyCellsAttribute () var tv = new TextView { Text = text }; tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.CursorPosition = new (18, 1); if (Environment.NewLine.Length == 2) { @@ -4739,9 +4737,10 @@ public void HistoryText_Undo_Redo_ApplyCellsAttribute () { Assert.Equal (30, tv.SelectedLength); } + Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList)); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.False (tv.IsDirty); AssertNullAttribute (); @@ -4753,7 +4752,7 @@ public void HistoryText_Undo_Redo_ApplyCellsAttribute () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList)); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.True (tv.IsDirty); // Undo @@ -4766,7 +4765,7 @@ public void HistoryText_Undo_Redo_ApplyCellsAttribute () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.Empty (tv.SelectedCellsList); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4779,7 +4778,7 @@ public void HistoryText_Undo_Redo_ApplyCellsAttribute () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.Empty (tv.SelectedCellsList); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), tv.CursorPosition); Assert.True (tv.IsDirty); void AssertNullAttribute () @@ -4880,7 +4879,7 @@ public void Internal_Tests () Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really")); Assert.Equal (Cell.StringToCells ("Threally really first line."), tm.GetLine (0)); Assert.Equal (Cell.StringToCells ("Threally really last line."), tm.GetLine (1)); - tm = new TextModel (); + tm = new (); tm.AddLine (0, Cell.StringToCells ("This is first line.")); tm.AddLine (1, Cell.StringToCells ("This is last line.")); Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really")); @@ -4914,12 +4913,12 @@ public void KeyBindings_Command () tv.CanFocus = true; Assert.False (tv.NewKeyDownEvent (Key.CursorLeft)); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal (2, tv.CurrentRow); Assert.Equal (23, tv.CurrentColumn); Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.False (tv.NewKeyDownEvent (Key.CursorRight)); Assert.NotNull (tv.Autocomplete); Assert.Empty (g.AllSuggestions); @@ -4930,7 +4929,7 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text ); - Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Equal (new (24, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); tv.Draw (); @@ -4939,7 +4938,7 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); tv.Draw (); @@ -4948,7 +4947,7 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text ); - Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Equal (new (24, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); @@ -4956,7 +4955,7 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text ); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); g.AllSuggestions = Regex.Matches (tv.Text, "\\w+") .Select (s => s.Value) @@ -4977,7 +4976,7 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text ); - Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Equal (new (24, 2), tv.CursorPosition); Assert.Single (tv.Autocomplete.Suggestions); Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement); Assert.True (tv.NewKeyDownEvent (Key.Enter)); @@ -4986,41 +4985,41 @@ public void KeyBindings_Command () $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (new (28, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.False (tv.Autocomplete.Visible); - g.AllSuggestions = new List (); + g.AllSuggestions = new (); tv.Autocomplete.ClearSuggestions (); Assert.Empty (g.AllSuggestions); Assert.Empty (tv.Autocomplete.Suggestions); Assert.True (tv.NewKeyDownEvent (Key.PageUp)); Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (24, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (Key.PageUp))); + Assert.Equal (new (24, 1), tv.CursorPosition); + Assert.True (tv.NewKeyDownEvent (new (Key.PageUp))); Assert.Equal (23, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 0), tv.CursorPosition); + Assert.Equal (new (23, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.PageDown)); Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.Equal (new (23, 1), tv.CursorPosition); // gets the previous length Assert.True (tv.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (new (23, 2), tv.CursorPosition); // gets the previous length Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.PageUp.WithShift)); Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.Equal (new (23, 1), tv.CursorPosition); // gets the previous length Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.PageDown.WithShift)); Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (new (23, 2), tv.CursorPosition); // gets the previous length Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl)); Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.N.WithCtrl)); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl)); @@ -5028,7 +5027,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorDown)); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorUp)); @@ -5036,7 +5035,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift)); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift)); @@ -5044,7 +5043,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl)); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl)); @@ -5052,7 +5051,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); @@ -5061,7 +5060,7 @@ public void KeyBindings_Command () Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift)); - Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (new (1, 0), tv.CursorPosition); Assert.Equal (1, tv.SelectedLength); Assert.Equal ("T", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5103,28 +5102,28 @@ public void KeyBindings_Command () $"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (21, 0), tv.CursorPosition); + Assert.Equal (new (21, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ( $"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (20, 0), tv.CursorPosition); + Assert.Equal (new (20, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ( $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Home)); Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); Assert.True (tv.NewKeyDownEvent (Key.End.WithShift)); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (19, tv.SelectedLength); Assert.Equal ("is is the first lin", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5134,7 +5133,7 @@ public void KeyBindings_Command () Assert.Equal ("", tv.SelectedText); Assert.True (tv.IsSelecting); Assert.True (tv.NewKeyDownEvent (Key.E.WithCtrl)); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5160,7 +5159,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5183,7 +5182,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5216,7 +5215,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5228,7 +5227,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5240,7 +5239,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5253,7 +5252,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (19, tv.SelectedLength); Assert.Equal ("is is the first lin", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5265,7 +5264,7 @@ public void KeyBindings_Command () $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (new (19, 0), tv.CursorPosition); Assert.Equal (19, tv.SelectedLength); Assert.Equal ("is is the first lin", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5316,7 +5315,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (new (28, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5326,7 +5325,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5336,7 +5335,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (new (12, 2), tv.CursorPosition); Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5346,7 +5345,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (8, 2), tv.CursorPosition); + Assert.Equal (new (8, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5356,7 +5355,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (new (12, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5366,7 +5365,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5376,7 +5375,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (22, 2), tv.CursorPosition); + Assert.Equal (new (22, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5386,7 +5385,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Equal (new (23, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5396,7 +5395,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (new (28, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5418,14 +5417,14 @@ public void KeyBindings_Command () Assert.False (tv.IsSelecting); Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 1), tv.CursorPosition); + Assert.Equal (new (28, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); Assert.False (tv.IsSelecting); Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (new (18, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5450,7 +5449,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text ); - Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (new (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.IsSelecting); @@ -5461,7 +5460,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text ); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); Assert.True (tv.IsSelecting); @@ -5481,7 +5480,7 @@ public void KeyBindings_Command () $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text ); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength); Assert.Equal ( @@ -5493,7 +5492,7 @@ public void KeyBindings_Command () Assert.True (tv.NewKeyDownEvent (Key.InsertChar)); Assert.False (tv.Used); Assert.True (tv.AllowsTab); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); tv.AllowsTab = false; Assert.False (tv.NewKeyDownEvent (Key.Tab)); @@ -5503,7 +5502,7 @@ public void KeyBindings_Command () ); Assert.False (tv.AllowsTab); tv.AllowsTab = true; - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (new (18, 2), tv.CursorPosition); Assert.True (tv.IsSelecting); tv.IsSelecting = false; Assert.True (tv.NewKeyDownEvent (Key.Tab)); @@ -5931,9 +5930,9 @@ public void Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste () break; case 1: _textView.NewKeyDownEvent ( - new Key ( - KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask - ) + new ( + KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask + ) ); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); @@ -5994,9 +5993,9 @@ public void Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste () break; case 1: _textView.NewKeyDownEvent ( - new Key ( - KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask - ) + new ( + KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask + ) ); Assert.Equal (23, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); @@ -6042,13 +6041,13 @@ public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width () Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.LeftColumn); - tv.CursorPosition = new Point (9, 0); - Assert.Equal (new Point (9, 0), tv.CursorPosition); + tv.CursorPosition = new (9, 0); + Assert.Equal (new (9, 0), tv.CursorPosition); Assert.Equal (0, tv.LeftColumn); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); - tv.CursorPosition = new Point (10, 0); - Assert.Equal (new Point (10, 0), tv.CursorPosition); + tv.CursorPosition = new (10, 0); + Assert.Equal (new (10, 0), tv.CursorPosition); Assert.Equal (1, tv.LeftColumn); } @@ -6175,62 +6174,62 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True ( _textView.NewMouseEvent ( - new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } - ) + new() { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + ) ); Assert.Equal (0, _textView.SelectionStartColumn); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (12, 0), _textView.CursorPosition); + Assert.Equal (new (12, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump ", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new() { Position = new (12, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (12, 0), _textView.CursorPosition); + Assert.Equal (new (12, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump ", _textView.SelectedText); Assert.True ( _textView.NewMouseEvent ( - new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } - ) + new() { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + ) ); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (19, 0), _textView.CursorPosition); + Assert.Equal (new (19, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new() { Position = new (19, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (19, 0), _textView.CursorPosition); + Assert.Equal (new (19, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between", _textView.SelectedText); Assert.True ( _textView.NewMouseEvent ( - new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } - ) + new() { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + ) ); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.Equal (new (24, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between text", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new() { Position = new (24, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.Equal (new (24, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between text", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed })); + Assert.True (_textView.NewMouseEvent (new() { Position = new (24, 0), Flags = MouseFlags.Button1Pressed })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); - Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.Equal (new (24, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("", _textView.SelectedText); } @@ -6248,11 +6247,11 @@ public void MoveDown_By_Setting_CursorPosition () } Assert.Equal (Point.Empty, tv.CursorPosition); - tv.CursorPosition = new Point (5, 50); - Assert.Equal (new Point (5, 50), tv.CursorPosition); + tv.CursorPosition = new (5, 50); + Assert.Equal (new (5, 50), tv.CursorPosition); - tv.CursorPosition = new Point (200, 200); - Assert.Equal (new Point (100, 99), tv.CursorPosition); + tv.CursorPosition = new (200, 200); + Assert.Equal (new (100, 99), tv.CursorPosition); } [Fact] @@ -6290,7 +6289,7 @@ public void Paste_Always_Clear_The_SelectedText () { _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); + _textView.CursorPosition = new (24, 0); _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste @@ -6344,8 +6343,8 @@ public void ScrollTo_CursorPosition () tv.ScrollTo (50); Assert.Equal (Point.Empty, tv.CursorPosition); - tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow); - Assert.Equal (new Point (0, 50), tv.CursorPosition); + tv.CursorPosition = new (tv.LeftColumn, tv.TopRow); + Assert.Equal (new (0, 50), tv.CursorPosition); } [Fact] @@ -6374,7 +6373,7 @@ public void Selected_Text_Shows () _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); Application.RunIteration (ref rs, true); - Assert.Equal (new Point (4, 0), _textView.CursorPosition); + Assert.Equal (new (4, 0), _textView.CursorPosition); // TAB to jump between text fields. DriverAssert.AssertDriverAttributesAre ("1111000", _output, Application.Driver, attributes); @@ -6386,7 +6385,7 @@ public void Selected_Text_Shows () [TextViewTestsAutoInitShutdown] public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length () { - _textView.CursorPosition = new Point (33, 2); + _textView.CursorPosition = new (33, 2); _textView.SelectionStartColumn = 33; _textView.SelectionStartRow = 33; Assert.Equal (32, _textView.CursorPosition.X); @@ -6401,8 +6400,8 @@ public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Cha [TextViewTestsAutoInitShutdown] public void Selection_With_Empty_Text () { - _textView = new TextView (); - _textView.CursorPosition = new Point (2, 0); + _textView = new (); + _textView.CursorPosition = new (2, 0); _textView.SelectionStartColumn = 33; _textView.SelectionStartRow = 1; Assert.Equal (0, _textView.SelectionStartColumn); @@ -6415,7 +6414,7 @@ public void Selection_With_Empty_Text () [TextViewTestsAutoInitShutdown] public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length () { - _textView.CursorPosition = new Point (2, 0); + _textView.CursorPosition = new (2, 0); _textView.SelectionStartColumn = 33; _textView.SelectionStartRow = 1; Assert.Equal (32, _textView.SelectionStartColumn); @@ -6483,7 +6482,7 @@ public void Tab_Test_Follow_By_BackTab () { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6492,7 +6491,7 @@ public void Tab_Test_Follow_By_BackTab () { col--; _textView.NewKeyDownEvent (Key.Tab.WithShift); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6519,14 +6518,14 @@ public void Tab_Test_Follow_By_BackTab_With_Text () Assert.Equal (10, _textView.Height); var col = 0; var leftCol = 0; - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); Assert.Equal (leftCol, _textView.LeftColumn); while (col < 100) { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6535,7 +6534,7 @@ public void Tab_Test_Follow_By_BackTab_With_Text () { col--; _textView.NewKeyDownEvent (Key.Tab.WithShift); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6569,7 +6568,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight () { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6578,7 +6577,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight () { col--; _textView.NewKeyDownEvent (Key.CursorLeft); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6587,7 +6586,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight () { col++; _textView.NewKeyDownEvent (Key.CursorRight); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6621,7 +6620,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Te { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6632,7 +6631,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Te { col--; _textView.NewKeyDownEvent (Key.CursorLeft); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6641,7 +6640,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Te { col++; _textView.NewKeyDownEvent (Key.CursorRight); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6668,7 +6667,7 @@ public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_Ba Assert.Equal (10, _textView.Height); var col = 0; var leftCol = 0; - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); Assert.Equal (leftCol, _textView.LeftColumn); Assert.Equal ("TAB to jump between text fields.", _textView.Text); Assert.Equal (32, _textView.Text.Length); @@ -6677,21 +6676,21 @@ public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_Ba { col++; _textView.NewKeyDownEvent (Key.Tab); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } _textView.NewKeyDownEvent (Key.Home); col = 0; - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = 0; Assert.Equal (leftCol, _textView.LeftColumn); _textView.NewKeyDownEvent (Key.End); col = _textView.Text.Length; Assert.Equal (132, _textView.Text.Length); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); string txt = _textView.Text; @@ -6701,14 +6700,14 @@ public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_Ba col--; } - _textView.CursorPosition = new Point (col, 0); + _textView.CursorPosition = new (col, 0); leftCol = GetLeftCol (leftCol); while (col > 0) { col--; _textView.NewKeyDownEvent (Key.Tab.WithShift); - Assert.Equal (new Point (col, 0), _textView.CursorPosition); + Assert.Equal (new (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } @@ -6746,19 +6745,19 @@ public void TabWidth_Setting_To_Zero_Keeps_AllowsTab () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TAB to jump between text field", - _output - ); + _output + ); _textView.TabWidth = 4; Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TAB to jump between text f", - _output - ); + _output + ); _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal ("TAB to jump between text fields.", _textView.Text); @@ -6766,10 +6765,10 @@ public void TabWidth_Setting_To_Zero_Keeps_AllowsTab () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" TAB to jump between text field", - _output - ); + _output + ); top.Dispose (); } @@ -6833,7 +6832,7 @@ public void TextView_InsertText_Newline_CRLF () //this passes Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -6849,10 +6848,10 @@ public void TextView_InsertText_Newline_CRLF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); - Assert.Equal (new Rectangle (0, 0, 15, 15), pos); + Assert.Equal (new (0, 0, 15, 15), pos); Assert.True (tv.Used); tv.Used = false; @@ -6861,7 +6860,7 @@ public void TextView_InsertText_Newline_CRLF () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -6877,8 +6876,8 @@ public void TextView_InsertText_Newline_CRLF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); top.Dispose (); } @@ -6911,7 +6910,7 @@ public void TextView_InsertText_Newline_LF () //this passes Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -6927,10 +6926,10 @@ public void TextView_InsertText_Newline_LF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); - Assert.Equal (new Rectangle (0, 0, 15, 15), pos); + Assert.Equal (new (0, 0, 15, 15), pos); Assert.True (tv.Used); tv.Used = false; @@ -6939,7 +6938,7 @@ public void TextView_InsertText_Newline_LF () Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -6955,8 +6954,8 @@ public void TextView_InsertText_Newline_LF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); top.Dispose (); } @@ -6985,7 +6984,7 @@ public void TextView_SpaceHandling () tv.NewMouseEvent (ev); Assert.Equal (1, tv.SelectedLength); - ev = new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }; + ev = new() { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }; tv.NewMouseEvent (ev); Assert.Equal (1, tv.SelectedLength); @@ -7012,35 +7011,35 @@ public void UnwrappedCursorPosition_Event () Assert.Equal (Point.Empty, cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); tv.WordWrap = true; - tv.CursorPosition = new Point (12, 0); + tv.CursorPosition = new (12, 0); tv.Draw (); - Assert.Equal (new Point (12, 0), tv.CursorPosition); - Assert.Equal (new Point (12, 0), cp); + Assert.Equal (new (12, 0), tv.CursorPosition); + Assert.Equal (new (12, 0), cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line. ", - _output - ); + _output + ); ((FakeDriver)Application.Driver).SetBufferSize (6, 25); tv.SetRelativeLayout (Application.Screen.Size); tv.Draw (); - Assert.Equal (new Point (4, 2), tv.CursorPosition); - Assert.Equal (new Point (12, 0), cp); + Assert.Equal (new (4, 2), tv.CursorPosition); + Assert.Equal (new (12, 0), cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the @@ -7054,16 +7053,16 @@ This is the second line. d line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); tv.Draw (); - Assert.Equal (new Point (0, 3), tv.CursorPosition); - Assert.Equal (new Point (12, 0), cp); + Assert.Equal (new (0, 3), tv.CursorPosition); + Assert.Equal (new (12, 0), cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the @@ -7077,16 +7076,16 @@ This is the second line. d line. ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); tv.Draw (); - Assert.Equal (new Point (1, 3), tv.CursorPosition); - Assert.Equal (new Point (13, 0), cp); + Assert.Equal (new (1, 3), tv.CursorPosition); + Assert.Equal (new (13, 0), cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the @@ -7100,16 +7099,16 @@ This is the second line. d line. ", - _output - ); + _output + ); - Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.Button1Pressed })); + Assert.True (tv.NewMouseEvent (new() { Position = new (0, 3), Flags = MouseFlags.Button1Pressed })); tv.Draw (); - Assert.Equal (new Point (0, 3), tv.CursorPosition); - Assert.Equal (new Point (13, 0), cp); + Assert.Equal (new (0, 3), tv.CursorPosition); + Assert.Equal (new (13, 0), cp); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the @@ -7123,8 +7122,8 @@ This is the second line. d line. ", - _output - ); + _output + ); top.Dispose (); } @@ -7133,7 +7132,7 @@ This is the second line. public void Used_Is_False () { _textView.Used = false; - _textView.CursorPosition = new Point (10, 0); + _textView.CursorPosition = new (10, 0); Assert.Equal ("TAB to jump between text fields.", _textView.Text); _textView.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumu between text fields.", _textView.Text); @@ -7149,7 +7148,7 @@ public void Used_Is_False () [TextViewTestsAutoInitShutdown] public void Used_Is_True_By_Default () { - _textView.CursorPosition = new Point (10, 0); + _textView.CursorPosition = new (10, 0); Assert.Equal ("TAB to jump between text fields.", _textView.Text); _textView.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumup between text fields.", _textView.Text); @@ -7338,7 +7337,7 @@ public void WordBackward_Multiline_With_Selection () [TextViewTestsAutoInitShutdown] public void WordBackward_With_No_Selection () { - _textView.CursorPosition = new Point (_textView.Text.Length, 0); + _textView.CursorPosition = new (_textView.Text.Length, 0); var iteration = 0; while (_textView.CursorPosition.X > 0) @@ -7423,7 +7422,7 @@ public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespac // 1 2 3 4 5 // 0123456789012345678901234567890123456789012345678901234=55 (Length) _textView.Text = "TAB t o jump b etween t ext f ields ."; - _textView.CursorPosition = new Point (_textView.Text.Length, 0); + _textView.CursorPosition = new (_textView.Text.Length, 0); var iteration = 0; while (_textView.CursorPosition.X > 0) @@ -7541,7 +7540,7 @@ public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespac [TextViewTestsAutoInitShutdown] public void WordBackward_With_Selection () { - _textView.CursorPosition = new Point (_textView.Text.Length, 0); + _textView.CursorPosition = new (_textView.Text.Length, 0); _textView.SelectionStartColumn = _textView.Text.Length; _textView.SelectionStartRow = 0; var iteration = 0; @@ -7626,7 +7625,7 @@ public void WordBackward_With_Selection () public void WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text () { - _textView.CursorPosition = new Point (10, 0); + _textView.CursorPosition = new (10, 0); _textView.SelectionStartColumn = 10; _textView.SelectionStartRow = 0; var iteration = 0; @@ -7699,9 +7698,9 @@ public void WordForward_Multiline_With_Selection () while (!iterationsFinished) { _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) + new ( + KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask + ) ); switch (iteration) @@ -8041,9 +8040,9 @@ public void WordForward_With_Selection () while (_textView.CursorPosition.X < _textView.Text.Length) { _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) + new ( + KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask + ) ); switch (iteration) @@ -8113,7 +8112,7 @@ public void WordForward_With_Selection () public void WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text () { - _textView.CursorPosition = new Point (10, 0); + _textView.CursorPosition = new (10, 0); _textView.SelectionStartColumn = 10; _textView.SelectionStartRow = 0; var iteration = 0; @@ -8121,9 +8120,9 @@ public void while (_textView.CursorPosition.X < _textView.Text.Length) { _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) + new ( + KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask + ) ); switch (iteration) @@ -8184,67 +8183,67 @@ public void WordWrap_Deleting_Backwards () Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" aaaa ", - _output - ); + _output + ); - tv.CursorPosition = new Point (5, 0); + tv.CursorPosition = new (5, 0); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.LayoutAndDraw (); Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" aaa ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.LayoutAndDraw (); Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" aa ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.LayoutAndDraw (); Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" a ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.LayoutAndDraw (); Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" ", - _output - ); + _output + ); Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.LayoutAndDraw (); Assert.Equal (0, tv.LeftColumn); DriverAssert.AssertDriverContentsAre ( - @" + @" ", - _output - ); + _output + ); top.Dispose (); } @@ -8263,16 +8262,16 @@ public void WordWrap_Draw_Typed_Keys_After_Text_Is_Deleted (KeyCode del) Assert.True (_textView.WordWrap); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" Line 1. Line 2.", - _output - ); + _output + ); Assert.True (_textView.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal ("Line 1.", _textView.SelectedText); - Assert.True (_textView.NewKeyDownEvent (new Key (del))); + Assert.True (_textView.NewKeyDownEvent (new (del))); Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ("Line 2.", _output); @@ -8281,11 +8280,11 @@ Line 1. Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" H Line 2.", - _output - ); + _output + ); top.Dispose (); } @@ -8338,7 +8337,7 @@ public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy () tv.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. @@ -8347,18 +8346,18 @@ This is second line. ", - _output - ); + _output + ); tv.ReadOnly = true; - tv.CursorPosition = new Point (6, 2); - Assert.Equal (new Point (5, 2), tv.CursorPosition); - top.LayoutSubviews (); + tv.CursorPosition = new (6, 2); + Assert.Equal (new (5, 2), tv.CursorPosition); + top.LayoutSubViews (); View.SetClipToScreen (); tv.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. @@ -8366,8 +8365,8 @@ This is the second line. ", - _output - ); + _output + ); tv.SelectionStartRow = 0; tv.SelectionStartColumn = 0; @@ -8444,7 +8443,7 @@ public void WordWrap_WrapModel_Output () tv.Draw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first @@ -8454,8 +8453,8 @@ This is second line. ", - _output - ); + _output + ); } private int GetLeftCol (int start) @@ -8543,12 +8542,11 @@ public override void Before (MethodInfo methodUnderTest) // 01234567890123456789012345678901=32 (Length) byte [] buff = Encoding.Unicode.GetBytes (Txt); byte [] ms = new MemoryStream (buff).ToArray (); - _textView = new TextView { Width = 30, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] }; + _textView = new() { Width = 30, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] }; _textView.Text = Encoding.Unicode.GetString (ms); } } - [Fact] public void HotKey_Command_SetsFocus () { @@ -8580,12 +8578,12 @@ public void HotKey_Command_Does_Not_Accept () [InlineData (true, 1)] public void Accepted_Command_Raises_Accepted_Regardles_Of_AllowsReturn (bool allowsReturn, int expectedAcceptEvents) { - var view = new TextView () + var view = new TextView { - AllowsReturn = allowsReturn, + AllowsReturn = allowsReturn }; - int acceptedEvents = 0; + var acceptedEvents = 0; view.Accepting += Accept; view.InvokeCommand (Command.Accept); Assert.Equal (expectedAcceptEvents, acceptedEvents); @@ -8600,12 +8598,12 @@ public void Accepted_Command_Raises_Accepted_Regardles_Of_AllowsReturn (bool all [InlineData (true, 0)] public void Enter_Key_Fires_Accepted_BasedOn_AllowsReturn (bool allowsReturn, int expectedAccepts) { - var view = new TextView () + var view = new TextView { - Multiline = allowsReturn, + Multiline = allowsReturn }; - int accepted = 0; + var accepted = 0; view.Accepting += Accept; view.NewKeyDownEvent (Key.Enter); Assert.Equal (expectedAccepts, accepted); @@ -8620,12 +8618,12 @@ public void Enter_Key_Fires_Accepted_BasedOn_AllowsReturn (bool allowsReturn, in [InlineData (true, 0)] public void Enter_Key_Fires_Accepted_BasedOn_Multiline (bool multiline, int expectedAccepts) { - var view = new TextView () + var view = new TextView { - Multiline = multiline, + Multiline = multiline }; - int accepted = 0; + var accepted = 0; view.Accepting += Accept; view.NewKeyDownEvent (Key.Enter); Assert.Equal (expectedAccepts, accepted); @@ -8635,13 +8633,10 @@ public void Enter_Key_Fires_Accepted_BasedOn_Multiline (bool multiline, int expe void Accept (object sender, CommandEventArgs e) { accepted++; } } - [Fact] public void Space_Key_Types_Space () { - var view = new TextView () - { - }; + var view = new TextView (); view.NewKeyDownEvent (Key.Space); @@ -8656,13 +8651,15 @@ public void Space_Key_Types_Space () public void Accepted_Event_Handled_Prevents_Default_Button_Accept (bool multiline, bool handleAccept, int expectedAccepts, int expectedButtonAccepts) { var superView = new Window (); - var tv = new TextView () + + var tv = new TextView { Multiline = multiline }; - var button = new Button () + + var button = new Button { - IsDefault = true, + IsDefault = true }; superView.Add (tv, button); @@ -8693,10 +8690,7 @@ void TextViewAccept (object sender, CommandEventArgs e) e.Cancel = handleAccept; } - void ButtonAccept (object sender, CommandEventArgs e) - { - buttonAccept++; - } + void ButtonAccept (object sender, CommandEventArgs e) { buttonAccept++; } } [Theory] @@ -8705,13 +8699,15 @@ void ButtonAccept (object sender, CommandEventArgs e) public void Accepted_No_Handler_Enables_Default_Button_Accept (bool multiline, int expectedButtonAccept) { var superView = new Window (); - var tv = new TextView () + + var tv = new TextView { Multiline = multiline }; - var button = new Button () + + var button = new Button { - IsDefault = true, + IsDefault = true }; superView.Add (tv, button); @@ -8731,10 +8727,7 @@ public void Accepted_No_Handler_Enables_Default_Button_Accept (bool multiline, i return; - void ButtonAccept (object sender, CommandEventArgs e) - { - buttonAccept++; - } + void ButtonAccept (object sender, CommandEventArgs e) { buttonAccept++; } } [Fact] @@ -8742,33 +8735,32 @@ public void Autocomplete_Popup_Added_To_SuperView_On_Init () { View superView = new () { - CanFocus = true, + CanFocus = true }; TextView t = new (); superView.Add (t); - Assert.Single (superView.Subviews); + Assert.Single (superView.SubViews); superView.BeginInit (); superView.EndInit (); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); } - [Fact] public void Autocomplete__Added_To_SuperView_On_Add () { View superView = new () { CanFocus = true, - Id = "superView", + Id = "superView" }; superView.BeginInit (); superView.EndInit (); - Assert.Empty (superView.Subviews); + Assert.Empty (superView.SubViews); TextView t = new () { @@ -8777,16 +8769,15 @@ public void Autocomplete__Added_To_SuperView_On_Add () superView.Add (t); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); } - [Fact] public void Autocomplete_Visible_False_By_Default () { View superView = new () { - CanFocus = true, + CanFocus = true }; TextView t = new (); @@ -8795,7 +8786,7 @@ public void Autocomplete_Visible_False_By_Default () superView.BeginInit (); superView.EndInit (); - Assert.Equal (2, superView.Subviews.Count); + Assert.Equal (2, superView.SubViews.Count); Assert.True (t.Visible); Assert.False (t.Autocomplete.Visible); @@ -8806,7 +8797,7 @@ public void Right_CursorAtEnd_WithSelection_ShouldClearSelection () { var tv = new TextView { - Text = "Hello", + Text = "Hello" }; tv.SetFocus (); @@ -8823,12 +8814,13 @@ public void Right_CursorAtEnd_WithSelection_ShouldClearSelection () // Now that the selection is cleared another right keypress should move focus Assert.False (tv.NewKeyDownEvent (Key.CursorRight)); } + [Fact] public void Left_CursorAtStart_WithSelection_ShouldClearSelection () { var tv = new TextView { - Text = "Hello", + Text = "Hello" }; tv.SetFocus (); @@ -8853,6 +8845,7 @@ public void Left_CursorAtStart_WithSelection_ShouldClearSelection () // Now that the selection is cleared another left keypress should move focus Assert.False (tv.NewKeyDownEvent (Key.CursorLeft)); } + [Fact] [AutoInitShutdown] public void Draw_Esc_Rune () @@ -8900,12 +8893,12 @@ public void CellEventArgs_WordWrap_True () ) ]; TextView tv = CreateTextView (); - tv.DrawNormalColor += textView_DrawColor; - tv.DrawReadOnlyColor += textView_DrawColor; - tv.DrawSelectionColor += textView_DrawColor; - tv.DrawUsedColor += textView_DrawColor; + tv.DrawNormalColor += TextView_DrawColor; + tv.DrawReadOnlyColor += TextView_DrawColor; + tv.DrawSelectionColor += TextView_DrawColor; + tv.DrawUsedColor += TextView_DrawColor; - void textView_DrawColor (object sender, CellEventArgs e) + void TextView_DrawColor (object sender, CellEventArgs e) { Assert.Equal (e.Line [e.Col], text [e.UnwrappedPosition.Row] [e.UnwrappedPosition.Col]); eventCount++; @@ -8919,11 +8912,11 @@ void textView_DrawColor (object sender, CellEventArgs e) Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first line. This is the second line.", - _output - ); + _output + ); tv.Width = 10; tv.Height = 25; @@ -8931,7 +8924,7 @@ This is the first line. Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsWithFrameAre ( - @" + @" This is the first @@ -8940,8 +8933,8 @@ This is the second line. ", - _output - ); + _output + ); Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2); top.Dispose (); @@ -9092,10 +9085,10 @@ public void Cell_LoadCells_Without_ColorScheme_Is_Never_Null () { List cells = new () { - new() { Rune = new ('T') }, - new() { Rune = new ('e') }, - new() { Rune = new ('s') }, - new() { Rune = new ('t') } + new () { Rune = new ('T') }, + new () { Rune = new ('e') }, + new () { Rune = new ('s') }, + new () { Rune = new ('t') } }; TextView tv = CreateTextView (); var top = new Toplevel (); diff --git a/Tests/UnitTests/Views/TileViewTests.cs b/Tests/UnitTests/Views/TileViewTests.cs index a8301280ea..41a4d1abcd 100644 --- a/Tests/UnitTests/Views/TileViewTests.cs +++ b/Tests/UnitTests/Views/TileViewTests.cs @@ -1,14 +1,10 @@ using UnitTests; -using UnitTests; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; -public class TileViewTests +public class TileViewTests (ITestOutputHelper output) { - private readonly ITestOutputHelper _output; - public TileViewTests (ITestOutputHelper output) { _output = output; } - [Fact] [AutoInitShutdown] public void Test_SplitTop_WholeBottom () @@ -20,13 +16,13 @@ public void Test_SplitTop_WholeBottom () Assert.True (tileView.TrySplitTile (0, 2, out TileView top)); - top.Tiles.ElementAt (0).ContentView.Add (new Label { Text = "bleh" }); - top.Tiles.ElementAt (1).ContentView.Add (new Label { Text = "blah" }); + top.Tiles.ElementAt (0).ContentView!.Add (new Label { Text = "bleh" }); + top.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "blah" }); top.Layout (); - tileView.Tiles.ElementAt (1).ContentView.Add (new Label { Text = "Hello" }); - tileView.ColorScheme = new ColorScheme (); - top.ColorScheme = new ColorScheme (); + tileView.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "Hello" }); + tileView.ColorScheme = new (); + top.ColorScheme = new (); top.Layout (); tileView.Layout (); @@ -45,7 +41,7 @@ public void Test_SplitTop_WholeBottom () │ │ └──────────────────┘"; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -58,7 +54,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 () Application.LayoutAndDraw (); - var looksLike = @" ┌────┬────┬────┬────┬───┐ @@ -66,7 +61,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 () │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 0; x <= 5; x++) { @@ -88,6 +83,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 () // the second splitter so are not allowed Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}"); } + Application.LayoutAndDraw (); looksLike = @@ -97,7 +93,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 () │ ││ │ │ │ └────────┴┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -110,7 +106,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder () Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -118,7 +113,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder () │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 0; x <= 5; x++) { @@ -151,7 +146,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder () ││ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -165,7 +160,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 () Application.LayoutAndDraw (); - var looksLike = @" ┌────┬────┬────┬────┬───┐ @@ -173,7 +167,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 () │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x > 7; x--) { @@ -187,7 +181,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 () Application.LayoutAndDraw (); - looksLike = @" ┌────┬──┬──────┬────┬───┐ @@ -195,7 +188,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 () │ │ │ │ │ │ └────┴──┴──────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x < 12; x++) { @@ -217,7 +210,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 () │ │ │ │ │ │ └────┴─────┴───┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -230,7 +223,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () tv.Tiles.ElementAt (2).MinSize = 3; Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -238,7 +230,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x > 7; x--) { @@ -252,7 +244,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () Application.LayoutAndDraw (); - looksLike = @" @@ -262,7 +253,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x < 12; x++) { @@ -276,7 +267,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () Application.LayoutAndDraw (); - looksLike = @" 11111│22222│333│4444│5555 @@ -285,7 +275,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder () │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -299,7 +289,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () Application.LayoutAndDraw (); - var looksLike = @" ┌────┬────┬────┬────┬───┐ @@ -307,7 +296,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x > 17; x--) { @@ -321,7 +310,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () Application.LayoutAndDraw (); - looksLike = @" ┌────┬────┬────┬──┬─────┐ @@ -330,7 +318,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () └────┴────┴────┴──┴─────┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x < 23; x++) { @@ -344,7 +332,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () Application.LayoutAndDraw (); - looksLike = @" ┌────┬────┬────┬──────┬─┐ @@ -352,7 +339,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 () │ │ │ │ │ │ └────┴────┴────┴──────┴─┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -366,7 +353,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -374,7 +360,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x > 17; x--) { @@ -388,7 +374,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () Application.LayoutAndDraw (); - looksLike = @" 11111│2222│3333│44│555555 @@ -396,7 +381,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x < 24; x++) { @@ -410,7 +395,6 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () Application.LayoutAndDraw (); - looksLike = @" 11111│2222│3333│4444444│5 @@ -418,7 +402,7 @@ public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder () │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -429,7 +413,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB Application.LayoutAndDraw (); - var looksLike = @" ┌────┬────┬────┬────┬───┐ @@ -437,7 +420,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 5; x > 0; x--) { @@ -448,7 +431,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB Application.LayoutAndDraw (); - looksLike = @" ┌┬────────┬────┬────┬───┐ @@ -456,7 +438,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB ││ │ │ │ │ └┴────────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 6; x < 10; x++) { @@ -472,7 +454,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB Application.LayoutAndDraw (); - looksLike = @" ┌────────┬┬────┬────┬───┐ @@ -480,7 +461,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB │ ││ │ │ │ └────────┴┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -491,7 +472,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -499,7 +479,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 5; x >= 0; x--) { @@ -508,7 +488,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB Application.LayoutAndDraw (); - looksLike = @" │222222222│3333│4444│5555 @@ -516,7 +495,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 6; x < 10; x++) { @@ -529,8 +508,8 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB // the second splitter so are not allowed Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}"); } - Application.LayoutAndDraw (); + Application.LayoutAndDraw (); looksLike = @" @@ -540,7 +519,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossB ││ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -558,7 +537,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x > 5; x--) { @@ -579,7 +558,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv │ ││ │ │ │ └────┴┴────────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x < 15; x++) { @@ -593,7 +572,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" ┌────┬────────┬┬────┬───┐ @@ -601,7 +579,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv │ │ ││ │ │ └────┴────────┴┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -612,7 +590,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -620,7 +597,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x > 5; x--) { @@ -631,8 +608,8 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv { Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}"); } - Application.LayoutAndDraw (); + Application.LayoutAndDraw (); looksLike = @" @@ -642,7 +619,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv ││ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 10; x < 15; x++) { @@ -656,7 +633,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" 11111│22222222││4444│5555 @@ -664,7 +640,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOv │ ││ │ │ ││ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -675,7 +651,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - var looksLike = @" ┌────┬────┬────┬────┬───┐ @@ -683,7 +658,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ │ │ │ │ └────┴────┴────┴────┴───┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x > 15; x--) { @@ -697,7 +672,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" ┌────┬────┬────┬┬───────┐ @@ -705,7 +679,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ │ ││ │ └────┴────┴────┴┴───────┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x < 24; x++) { @@ -719,7 +693,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" ┌────┬────┬────┬───────┬┐ @@ -727,7 +700,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ │ │ ││ └────┴────┴────┴───────┴┘ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -738,7 +711,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - var looksLike = @" 11111│2222│3333│4444│5555 @@ -746,7 +718,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x > 15; x--) { @@ -760,7 +732,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" 11111│2222│3333││55555555 @@ -769,7 +740,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ ││ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); for (var x = 20; x < 25; x++) { @@ -783,7 +754,6 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv Application.LayoutAndDraw (); - looksLike = @" 11111│2222│3333│44444444│ @@ -791,7 +761,7 @@ public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOv │ │ │ │ │ │ │ │ "; - DriverAssert.AssertDriverContentsAre (looksLike, _output); + DriverAssert.AssertDriverContentsAre (looksLike, output); } [Fact] @@ -810,6 +780,7 @@ public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile () tv.InsertTile (2); // but I still want my view in the first tile + // BUGBUG: Adding a view twice is not legit tv.Tiles.ElementAt (0).ContentView.Add (myReusableView); Assert.Multiple ( @@ -837,6 +808,7 @@ public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount tv.RebuildForTileCount (3); // but I still want my view in the first tile + // BUGBUG: Adding a view twice is not legit tv.Tiles.ElementAt (0).ContentView.Add (myReusableView); Assert.Multiple ( @@ -865,6 +837,7 @@ public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx) tv.RemoveTile (idx); // but I still want my view in the first tile + // BUGBUG: Adding a view twice is not legit tv.Tiles.ElementAt (0).ContentView.Add (myReusableView); Assert.Multiple ( @@ -891,11 +864,11 @@ public void TestNestedContainer2LeftAnd1Right_RendersNicely () var left = (TileView)tileView.Tiles.ElementAt (0).ContentView; Assert.Same (left.SuperView, tileView); - Assert.Equal (2, left.Tiles.ElementAt (0).ContentView.Subviews.Count); - Assert.IsType