Merge pull request #2501 from tig/v2_fixes_2492_nullable_warnings

Fixes #2492. Nullable warnings and other unit tests
This commit is contained in:
Tig
2023-04-04 16:58:49 -06:00
committed by GitHub
7 changed files with 114 additions and 88 deletions

View File

@@ -857,7 +857,7 @@ namespace Terminal.Gui {
/// <summary>
/// Gets or sets the <see cref="Terminal.Gui.TextFormatter"/> which can be handled differently by any derived class.
/// </summary>
public TextFormatter? TextFormatter { get; set; }
public TextFormatter TextFormatter { get; set; }
/// <summary>
/// Returns the container for this view, or null if this view has not been added to a container.

View File

@@ -128,7 +128,7 @@ namespace UICatalog.Scenarios {
};
label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";
const string rule = "0123456789";
//const string rule = "0123456789";
var horizontalRuler = new Label () {
X = 0,
@@ -140,7 +140,7 @@ namespace UICatalog.Scenarios {
};
scrollView.Add (horizontalRuler);
const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
//const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
var verticalRuler = new Label () {
X = 0,

View File

@@ -13,6 +13,7 @@ using System.Threading;
using Terminal.Gui.Configuration;
using static Terminal.Gui.Configuration.ConfigurationManager;
using System.Text.Json.Serialization;
using System.ComponentModel.DataAnnotations;
#nullable enable
@@ -70,7 +71,6 @@ namespace UICatalog {
_scenarios = Scenario.GetScenarios ();
_categories = Scenario.GetAllCategories ();
_nameColumnWidth = _scenarios.OrderByDescending (s => s.GetName ().Length).FirstOrDefault ().GetName ().Length;
if (args.Length > 0 && args.Contains ("-usc")) {
_useSystemConsole = true;
@@ -83,7 +83,7 @@ namespace UICatalog {
// run it and exit when done.
if (args.Length > 0) {
var item = _scenarios.FindIndex (s => s.GetName ().Equals (args [0], StringComparison.OrdinalIgnoreCase));
_selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ());
_selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ())!;
Application.UseSystemConsole = _useSystemConsole;
Application.Init ();
_selectedScenario.Theme = _cachedTheme;
@@ -115,7 +115,7 @@ namespace UICatalog {
Scenario scenario;
while ((scenario = RunUICatalogTopLevel ()) != null) {
VerifyObjectsWereDisposed ();
ConfigurationManager.Themes.Theme = _cachedTheme;
ConfigurationManager.Themes!.Theme = _cachedTheme!;
ConfigurationManager.Apply ();
scenario.Theme = _cachedTheme;
scenario.TopLevelColorScheme = _topLevelColorScheme;
@@ -151,7 +151,7 @@ namespace UICatalog {
// Setup a file system watcher for `./.tui/`
_currentDirWatcher.NotifyFilter = NotifyFilters.LastWrite;
var f = new FileInfo (Assembly.GetExecutingAssembly ().Location);
var tuiDir = Path.Combine (f.Directory.FullName, ".tui");
var tuiDir = Path.Combine (f.Directory!.FullName, ".tui");
if (!Directory.Exists (tuiDir)) {
Directory.CreateDirectory (tuiDir);
@@ -206,9 +206,9 @@ namespace UICatalog {
Application.Init ();
if (_cachedTheme is null) {
_cachedTheme = ConfigurationManager.Themes.Theme;
_cachedTheme = ConfigurationManager.Themes?.Theme;
} else {
ConfigurationManager.Themes.Theme = _cachedTheme;
ConfigurationManager.Themes!.Theme = _cachedTheme;
ConfigurationManager.Apply ();
}
@@ -217,40 +217,40 @@ namespace UICatalog {
Application.Run<UICatalogTopLevel> ();
Application.Shutdown ();
return _selectedScenario;
return _selectedScenario!;
}
static List<Scenario> _scenarios;
static List<string> _categories;
static int _nameColumnWidth;
static List<Scenario>? _scenarios;
static List<string>? _categories;
// When a scenario is run, the main app is killed. These items
// are therefore cached so that when the scenario exits the
// main app UI can be restored to previous state
static int _cachedScenarioIndex = 0;
static int _cachedCategoryIndex = 0;
static string? _cachedTheme;
static StringBuilder _aboutMessage;
static string? _cachedTheme = string.Empty;
static StringBuilder? _aboutMessage = null;
// If set, holds the scenario the user selected
static Scenario _selectedScenario = null;
static Scenario? _selectedScenario = null;
static bool _useSystemConsole = false;
static ConsoleDriver.DiagnosticFlags _diagnosticFlags;
//static bool _enableConsoleScrolling = false;
static bool _isFirstRunning = true;
static string _topLevelColorScheme;
static MenuItem [] _themeMenuItems;
static MenuBarItem _themeMenuBarItem;
static string _topLevelColorScheme = string.Empty;
static MenuItem []? _themeMenuItems;
static MenuBarItem? _themeMenuBarItem;
/// <summary>
/// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on
/// the command line) and each time a Scenario ends.
/// </summary>
public class UICatalogTopLevel : Toplevel {
public MenuItem miIsMouseDisabled;
public MenuItem miEnableConsoleScrolling;
public MenuItem? miIsMouseDisabled;
public MenuItem? miEnableConsoleScrolling;
public TileView ContentPane;
public ListView CategoryListView;
@@ -276,7 +276,7 @@ namespace UICatalog {
new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui/articles/overview.html"), null, null, Key.F1),
new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"), null, null, Key.F2),
new MenuItem ("_About...",
"About UI Catalog", () => MessageBox.Query ("About UI Catalog", _aboutMessage.ToString(), 0, false, "_Ok"), null, null, Key.CtrlMask | Key.A),
"About UI Catalog", () => MessageBox.Query ("About UI Catalog", _aboutMessage!.ToString(), 0, false, "_Ok"), null, null, Key.CtrlMask | Key.A),
}),
});
@@ -302,7 +302,7 @@ namespace UICatalog {
}),
new StatusItem(Key.F10, "~F10~ Status Bar", () => {
StatusBar.Visible = !StatusBar.Visible;
ContentPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
ContentPane!.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
LayoutSubviews();
SetSubViewNeedsDisplay();
}),
@@ -332,7 +332,7 @@ namespace UICatalog {
CanFocus = true,
};
CategoryListView.OpenSelectedItem += (s,a) => {
ScenarioListView.SetFocus ();
ScenarioListView!.SetFocus ();
};
CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
@@ -371,12 +371,12 @@ namespace UICatalog {
ConfigurationManager.Applied += ConfigAppliedHandler;
}
void LoadedHandler (object sender, EventArgs args)
void LoadedHandler (object? sender, EventArgs? args)
{
ConfigChanged ();
miIsMouseDisabled.Checked = Application.IsMouseDisabled;
miEnableConsoleScrolling.Checked = Application.EnableConsoleScrolling;
miIsMouseDisabled!.Checked = Application.IsMouseDisabled;
miEnableConsoleScrolling!.Checked = Application.EnableConsoleScrolling;
DriverName.Title = $"Driver: {Driver.GetType ().Name}";
OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem} {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion}";
@@ -391,7 +391,7 @@ namespace UICatalog {
StatusBar.VisibleChanged += (s, e) => {
UICatalogApp.ShowStatusBar = StatusBar.Visible;
var height = (StatusBar.Visible ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
var height = (StatusBar.Visible ? 1 : 0);
ContentPane.Height = Dim.Fill (height);
LayoutSubviews ();
SetSubViewNeedsDisplay ();
@@ -400,13 +400,13 @@ namespace UICatalog {
Loaded -= LoadedHandler;
}
private void UnloadedHandler (object sender, EventArgs args)
private void UnloadedHandler (object? sender, EventArgs? args)
{
ConfigurationManager.Applied -= ConfigAppliedHandler;
Unloaded -= UnloadedHandler;
}
void ConfigAppliedHandler (object sender, ConfigurationManagerEventArgs a)
void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a)
{
ConfigChanged ();
}
@@ -415,14 +415,16 @@ namespace UICatalog {
/// Launches the selected scenario, setting the global _selectedScenario
/// </summary>
/// <param name="e"></param>
void ScenarioListView_OpenSelectedItem (object sender, EventArgs e)
void ScenarioListView_OpenSelectedItem (object? sender, EventArgs? e)
{
if (_selectedScenario is null) {
// Save selected item state
_cachedCategoryIndex = CategoryListView.SelectedItem;
_cachedScenarioIndex = ScenarioListView.SelectedItem;
// Create new instance of scenario (even though Scenarios contains instances)
_selectedScenario = (Scenario)Activator.CreateInstance (ScenarioListView.Source.ToList () [ScenarioListView.SelectedItem].GetType ());
var sourceList = ScenarioListView.Source.ToList ();
_selectedScenario = (Scenario)Activator.CreateInstance (ScenarioListView.Source.ToList () [ScenarioListView.SelectedItem]!.GetType ())!;
// Tell the main app to stop
Application.RequestStop ();
@@ -431,12 +433,13 @@ namespace UICatalog {
List<MenuItem []> CreateDiagnosticMenuItems ()
{
List<MenuItem []> menuItems = new List<MenuItem []> ();
menuItems.Add (CreateDiagnosticFlagsMenuItems ());
menuItems.Add (new MenuItem [] { null });
menuItems.Add (CreateEnableConsoleScrollingMenuItems ());
menuItems.Add (CreateDisabledEnabledMouseItems ());
menuItems.Add (CreateKeybindingsMenuItems ());
List<MenuItem []> menuItems = new List<MenuItem []> {
CreateDiagnosticFlagsMenuItems (),
new MenuItem [] { },
CreateEnableConsoleScrollingMenuItems (),
CreateDisabledEnabledMouseItems (),
CreateKeybindingsMenuItems ()
};
return menuItems;
}
@@ -446,10 +449,10 @@ namespace UICatalog {
miIsMouseDisabled = new MenuItem {
Title = "_Disable Mouse"
};
miIsMouseDisabled.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miIsMouseDisabled.Title.ToString ().Substring (1, 1) [0];
miIsMouseDisabled.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miIsMouseDisabled!.Title!.ToString ()!.Substring (1, 1) [0];
miIsMouseDisabled.CheckType |= MenuItemCheckStyle.Checked;
miIsMouseDisabled.Action += () => {
miIsMouseDisabled.Checked = Application.IsMouseDisabled = (bool)!miIsMouseDisabled.Checked;
miIsMouseDisabled.Checked = Application.IsMouseDisabled = (bool)!miIsMouseDisabled.Checked!;
};
menuItems.Add (miIsMouseDisabled);
@@ -468,7 +471,7 @@ namespace UICatalog {
Application.Run (dlg);
};
menuItems.Add (null);
menuItems.Add (null!);
menuItems.Add (item);
return menuItems.ToArray ();
@@ -479,11 +482,11 @@ namespace UICatalog {
List<MenuItem> menuItems = new List<MenuItem> ();
miEnableConsoleScrolling = new MenuItem ();
miEnableConsoleScrolling.Title = "_Enable Console Scrolling";
miEnableConsoleScrolling.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miEnableConsoleScrolling.Title.ToString ().Substring (1, 1) [0];
miEnableConsoleScrolling.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miEnableConsoleScrolling.Title.ToString ()!.Substring (1, 1) [0];
miEnableConsoleScrolling.CheckType |= MenuItemCheckStyle.Checked;
miEnableConsoleScrolling.Action += () => {
miEnableConsoleScrolling.Checked = !miEnableConsoleScrolling.Checked;
Application.EnableConsoleScrolling = (bool)miEnableConsoleScrolling.Checked;
Application.EnableConsoleScrolling = (bool)miEnableConsoleScrolling.Checked!;
};
menuItems.Add (miEnableConsoleScrolling);
@@ -554,10 +557,10 @@ namespace UICatalog {
Enum GetDiagnosticsEnumValue (ustring title)
{
return title.ToString () switch {
return title!.ToString () switch {
FRAME_RULER => ConsoleDriver.DiagnosticFlags.FrameRuler,
FRAME_PADDING => ConsoleDriver.DiagnosticFlags.FramePadding,
_ => null,
_ => null!,
};
}
@@ -585,10 +588,10 @@ namespace UICatalog {
}
}
public MenuItem [] CreateThemeMenuItems ()
public MenuItem []? CreateThemeMenuItems ()
{
List<MenuItem> menuItems = new List<MenuItem> ();
foreach (var theme in ConfigurationManager.Themes) {
foreach (var theme in ConfigurationManager.Themes!) {
var item = new MenuItem {
Title = theme.Key,
Shortcut = Key.AltMask + theme.Key [0]
@@ -621,7 +624,7 @@ namespace UICatalog {
};
schemeMenuItems.Add (item);
}
menuItems.Add (null);
menuItems.Add (null!);
var mbi = new MenuBarItem ("_Color Scheme for Application.Top", schemeMenuItems.ToArray ());
menuItems.Add (mbi);
@@ -635,18 +638,19 @@ namespace UICatalog {
}
_themeMenuItems = ((UICatalogTopLevel)Application.Top).CreateThemeMenuItems ();
_themeMenuBarItem.Children = _themeMenuItems;
_themeMenuBarItem!.Children = _themeMenuItems;
var checkedThemeMenu = _themeMenuItems.Where (m => (bool)m.Checked).FirstOrDefault ();
var checkedThemeMenu = _themeMenuItems?.Where (m => m?.Checked ?? false).FirstOrDefault ();
if (checkedThemeMenu != null) {
checkedThemeMenu.Checked = false;
}
checkedThemeMenu = _themeMenuItems.Where (m => m != null && m.Title == ConfigurationManager.Themes.Theme).FirstOrDefault ();
checkedThemeMenu = _themeMenuItems?.Where (m => m != null && m.Title == ConfigurationManager.Themes?.Theme).FirstOrDefault ();
if (checkedThemeMenu != null) {
ConfigurationManager.Themes.Theme = checkedThemeMenu.Title.ToString ();
ConfigurationManager.Themes!.Theme = checkedThemeMenu.Title.ToString ()!;
checkedThemeMenu.Checked = true;
}
var schemeMenuItems = ((MenuBarItem)_themeMenuItems.Where (i => i is MenuBarItem).FirstOrDefault ()).Children;
var schemeMenuItems = ((MenuBarItem)_themeMenuItems?.Where (i => i is MenuBarItem)!.FirstOrDefault ()!)!.Children;
foreach (var schemeMenuItem in schemeMenuItems) {
schemeMenuItem.Checked = (string)schemeMenuItem.Data == _topLevelColorScheme;
}
@@ -659,8 +663,8 @@ namespace UICatalog {
StatusBar.Items [0].Shortcut = Application.QuitKey;
StatusBar.Items [0].Title = $"~{Application.QuitKey} to quit";
miIsMouseDisabled.Checked = Application.IsMouseDisabled;
miEnableConsoleScrolling.Checked = Application.EnableConsoleScrolling;
miIsMouseDisabled!.Checked = Application.IsMouseDisabled;
miEnableConsoleScrolling!.Checked = Application.EnableConsoleScrolling;
var height = (UICatalogApp.ShowStatusBar ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
ContentPane.Height = Dim.Fill (height);
@@ -670,9 +674,9 @@ namespace UICatalog {
Application.Top.SetNeedsDisplay ();
}
void KeyDownHandler (object sender, KeyEventEventArgs a)
void KeyDownHandler (object? sender, KeyEventEventArgs? a)
{
if (a.KeyEvent.IsCapslock) {
if (a!.KeyEvent.IsCapslock) {
Capslock.Title = "Caps: On";
StatusBar.SetNeedsDisplay ();
} else {
@@ -680,7 +684,7 @@ namespace UICatalog {
StatusBar.SetNeedsDisplay ();
}
if (a.KeyEvent.IsNumlock) {
if (a!.KeyEvent.IsNumlock) {
Numlock.Title = "Num: On";
StatusBar.SetNeedsDisplay ();
} else {
@@ -688,7 +692,7 @@ namespace UICatalog {
StatusBar.SetNeedsDisplay ();
}
if (a.KeyEvent.IsScrolllock) {
if (a!.KeyEvent.IsScrolllock) {
Scrolllock.Title = "Scroll: On";
StatusBar.SetNeedsDisplay ();
} else {
@@ -697,16 +701,16 @@ namespace UICatalog {
}
}
void CategoryListView_SelectedChanged (object sender, ListViewItemEventArgs e)
void CategoryListView_SelectedChanged (object? sender, ListViewItemEventArgs? e)
{
var item = _categories [e.Item];
var item = _categories! [e!.Item];
List<Scenario> newlist;
if (e.Item == 0) {
// First category is "All"
newlist = _scenarios;
newlist = _scenarios!;
} else {
newlist = _scenarios.Where (s => s.GetCategories ().Contains (item)).ToList ();
newlist = _scenarios!.Where (s => s.GetCategories ().Contains (item)).ToList ();
}
ScenarioListView.SetSource (newlist.ToList ());
}

View File

@@ -28,8 +28,8 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
/// </summary>
/// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
/// <param name="autoShutdown">If true, Application.Shutdown will be called After the test runs.</param>
/// <param name="consoleDriverType">Determins which ConsoleDriver (FakeDriver, WindowsDriver,
/// CursesDriver, NetDriver) will be used when Appliation.Init is called. If null FakeDriver will be used.
/// <param name="consoleDriverType">Determines which ConsoleDriver (FakeDriver, WindowsDriver,
/// CursesDriver, NetDriver) will be used when Application.Init is called. If null FakeDriver will be used.
/// Only valid if <paramref name="autoInit"/> is true.</param>
/// <param name="useFakeClipboard">If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>.
/// Only valid if <see cref="consoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.</param>
@@ -126,7 +126,7 @@ class TestHelpers {
actualLook = actualLook.Replace ("\r\n", "\n");
// If test is about to fail show user what things looked like
if(!string.Equals(expectedLook,actualLook)) {
if (!string.Equals (expectedLook, actualLook)) {
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
}
@@ -282,4 +282,3 @@ class TestHelpers {
return $"{a.Foreground},{a.Background}";
}
}

View File

@@ -12,7 +12,7 @@ using Xunit.Abstractions;
using Rune = System.Rune;
namespace Terminal.Gui.ViewTests {
#if false // BUGBUG: v2 see https://github.com/gui-cs/Terminal.Gui/issues/2463
// BUGBUG: v2 see https://github.com/gui-cs/Terminal.Gui/issues/2463
#region Helper Classes
class FakeHAxis : HorizontalAxis {
@@ -86,6 +86,8 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.ColorScheme = new ColorScheme ();
gv.MarginBottom = 1;
gv.MarginLeft = 1;
@@ -100,6 +102,8 @@ namespace Terminal.Gui.ViewTests {
public void ScreenToGraphSpace_DefaultCellSize ()
{
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
// origin should be bottom left
@@ -119,7 +123,7 @@ namespace Terminal.Gui.ViewTests {
public void ScreenToGraphSpace_DefaultCellSize_WithMargin ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -155,7 +159,7 @@ namespace Terminal.Gui.ViewTests {
public void ScreenToGraphSpace_CustomCellSize ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -186,7 +190,7 @@ namespace Terminal.Gui.ViewTests {
public void GraphSpaceToScreen_DefaultCellSize ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -205,7 +209,7 @@ namespace Terminal.Gui.ViewTests {
public void GraphSpaceToScreen_DefaultCellSize_WithMargin ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -234,7 +238,7 @@ namespace Terminal.Gui.ViewTests {
public void GraphSpaceToScreen_ScrollOffset ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -255,7 +259,7 @@ namespace Terminal.Gui.ViewTests {
public void GraphSpaceToScreen_CustomCellSize ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -295,7 +299,7 @@ namespace Terminal.Gui.ViewTests {
public void GraphSpaceToScreen_CustomCellSize_WithScrollOffset ()
{
var gv = new GraphView ();
gv.LayoutSubviews ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 20, 10);
@@ -340,6 +344,8 @@ namespace Terminal.Gui.ViewTests {
InitFakeDriver ();
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.ColorScheme = new ColorScheme ();
gv.Bounds = new Rect (0, 0, 50, 30);
gv.Series.Add (new ScatterSeries () { Points = new List<PointF> { new PointF (1, 1) } });
@@ -363,6 +369,7 @@ namespace Terminal.Gui.ViewTests {
public void TestReversing_ScreenToGraphSpace ()
{
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.Bounds = new Rect (0, 0, 50, 30);
// How much graph space each cell of the console depicts
@@ -414,6 +421,7 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.ColorScheme = new ColorScheme ();
gv.Bounds = new Rect (0, 0, 50, 30);
@@ -460,6 +468,7 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.ColorScheme = new ColorScheme ();
gv.Bounds = new Rect (0, 0, 50, 30);
@@ -683,6 +692,7 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var gv = new GraphView ();
gv.BeginInit (); gv.EndInit ();
gv.ColorScheme = new ColorScheme ();
// y axis goes from 0.1 to 1 across 10 console rows
@@ -1601,5 +1611,5 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (6.6f, render.Value);
}
}
#endif
}

View File

@@ -3,7 +3,7 @@ using Terminal.Gui;
using Xunit;
using Xunit.Abstractions;
namespace UnitTests.Views {
namespace Terminal.Gui.ViewsTests {
public class SpinnerViewTests {
readonly ITestOutputHelper output;
@@ -23,11 +23,11 @@ namespace UnitTests.Views {
Assert.NotEmpty (Application.MainLoop.timeouts);
//More calls to AutoSpin do not add more timeouts
Assert.Equal (1,Application.MainLoop.timeouts.Count);
Assert.Single (Application.MainLoop.timeouts);
view.AutoSpin ();
view.AutoSpin ();
view.AutoSpin ();
Assert.Equal (1, Application.MainLoop.timeouts.Count);
Assert.Single (Application.MainLoop.timeouts);
// Dispose clears timeout
Assert.NotEmpty (Application.MainLoop.timeouts);

View File

@@ -12,7 +12,6 @@ using System.Reflection;
namespace Terminal.Gui.ViewTests {
public class TableViewTests {
#if false // BUGBUG: v2 - Table scenarios are working fine; Will fix these unit test later
readonly ITestOutputHelper output;
public TableViewTests (ITestOutputHelper output)
@@ -267,6 +266,8 @@ namespace Terminal.Gui.ViewTests {
// ensure that TableView has the input focus
Application.Top.Add (tableView);
Application.Begin (Application.Top);
Application.Top.FocusFirst ();
Assert.True (tableView.HasFocus);
@@ -294,6 +295,7 @@ namespace Terminal.Gui.ViewTests {
MultiSelect = true,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
tableView.SelectAll ();
Assert.Equal (16, tableView.GetAllSelectedCells ().Count ());
@@ -321,6 +323,7 @@ namespace Terminal.Gui.ViewTests {
MultiSelect = true,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
tableView.ChangeSelectionToEndOfTable (false);
@@ -349,6 +352,7 @@ namespace Terminal.Gui.ViewTests {
MultiSelect = multiSelect,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
tableView.SetSelection (1, 1, false);
@@ -365,6 +369,7 @@ namespace Terminal.Gui.ViewTests {
MultiSelect = true,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
// move cursor to 1,1
tableView.SetSelection (1, 1, false);
@@ -390,6 +395,7 @@ namespace Terminal.Gui.ViewTests {
FullRowSelect = true,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
// move cursor to 1,1
tableView.SetSelection (1, 1, false);
@@ -416,6 +422,7 @@ namespace Terminal.Gui.ViewTests {
MultiSelect = true,
Bounds = new Rect (0, 0, 10, 5)
};
tableView.BeginInit (); tableView.EndInit ();
/*
Sets up disconnected selections like:
@@ -1002,7 +1009,7 @@ namespace Terminal.Gui.ViewTests {
private TableView SetUpMiniTable ()
{
var tv = new TableView ();
tv.LayoutSubviews ();
tv.BeginInit (); tv.EndInit ();
tv.Bounds = new Rect (0, 0, 10, 4);
var dt = new DataTable ();
@@ -1026,10 +1033,10 @@ namespace Terminal.Gui.ViewTests {
public void ScrollDown_OneLineAtATime ()
{
var tableView = new TableView ();
tableView.BeginInit (); tableView.EndInit ();
// Set big table
tableView.Table = BuildTable (25, 50);
tableView.LayoutSubviews ();
// 1 header + 4 rows visible
tableView.Bounds = new Rect (0, 0, 25, 5);
@@ -1054,6 +1061,8 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var tableView = new TableView ();
tableView.BeginInit (); tableView.EndInit ();
tableView.ColorScheme = Colors.TopLevel;
tableView.LayoutSubviews ();
@@ -1120,7 +1129,7 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var tableView = new TableView ();
tableView.LayoutSubviews ();
tableView.BeginInit (); tableView.EndInit ();
tableView.ColorScheme = Colors.TopLevel;
// 3 columns are visibile
@@ -1183,7 +1192,8 @@ namespace Terminal.Gui.ViewTests {
private TableView GetABCDEFTableView (out DataTable dt)
{
var tableView = new TableView ();
tableView.LayoutSubviews ();
tableView.BeginInit (); tableView.EndInit ();
tableView.ColorScheme = Colors.TopLevel;
// 3 columns are visible
@@ -1742,7 +1752,8 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var tableView = new TableView ();
tableView.LayoutSubviews ();
tableView.BeginInit (); tableView.EndInit ();
tableView.ColorScheme = Colors.TopLevel;
// 25 characters can be printed into table
@@ -1884,6 +1895,8 @@ namespace Terminal.Gui.ViewTests {
GraphViewTests.InitFakeDriver ();
var tableView = new TableView ();
tableView.BeginInit (); tableView.EndInit ();
tableView.ColorScheme = Colors.TopLevel;
// 3 columns are visibile
@@ -1987,6 +2000,7 @@ namespace Terminal.Gui.ViewTests {
public void Test_ScreenToCell ()
{
var tableView = GetTwoRowSixColumnTable ();
tableView.BeginInit (); tableView.EndInit ();
tableView.LayoutSubviews ();
tableView.Redraw (tableView.Bounds);
@@ -2162,6 +2176,5 @@ namespace Terminal.Gui.ViewTests {
tableView.Table = dt;
return tableView;
}
#endif
}
}