enabled posdim tests

This commit is contained in:
Charlie Kindel
2020-06-08 18:02:18 -06:00
parent 01c583f063
commit f8d235a426
7 changed files with 258 additions and 63 deletions

View File

@@ -222,7 +222,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
return $"Pos.Combine ({left.ToString ()}{(add ? '+' : '-')}{right.ToString ()})";
return $"Pos.Combine({left.ToString ()}{(add ? '+' : '-')}{right.ToString ()})";
}
}
@@ -274,7 +274,7 @@ namespace Terminal.Gui {
}
internal override int Anchor (int width)
{
switch (side) {
switch(side) {
case 0: return Target.Frame.X;
case 1: return Target.Frame.Y;
case 2: return Target.Frame.Right;
@@ -287,14 +287,14 @@ namespace Terminal.Gui {
public override string ToString ()
{
string tside;
switch (side) {
switch(side) {
case 0: tside = "x"; break;
case 1: tside = "y"; break;
case 2: tside = "right"; break;
case 3: tside = "bottom"; break;
default: tside = "unknown"; break;
}
return $"Pos.View(side={tside}, target={Target.ToString ()}";
return $"Pos.View(side={tside}, target={Target.ToString ()})";
}
}
@@ -538,9 +538,20 @@ namespace Terminal.Gui {
this.side = side;
}
public override string ToString ()
{
string tside;
switch(side) {
case 0: tside = "Height"; break;
case 1: tside = "Width"; break;
default: tside = "unknown"; break;
}
return $"DimView(side={tside}, target={Target.ToString ()})";
}
internal override int Anchor (int width)
{
switch (side) {
switch(side) {
case 0: return Target.Frame.Height;
case 1: return Target.Frame.Width;
default:

View File

@@ -5,7 +5,7 @@ using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.MockConsole;
using Console = Terminal.Gui.FakeConsole;
// Since Application is a singleton we can't run tests in parallel
[assembly: CollectionBehavior (DisableTestParallelization = true)]
@@ -13,7 +13,7 @@ using Console = Terminal.Gui.MockConsole;
namespace Terminal.Gui {
public class ApplicationTests {
[Fact]
public void TestInitShutdown ()
public void Init_Shutdown_Cleans_Up ()
{
Assert.Null (Application.Current);
Assert.Null (Application.CurrentView);
@@ -21,7 +21,7 @@ namespace Terminal.Gui {
Assert.Null (Application.MainLoop);
Assert.Null (Application.Driver);
Application.Init (new MockDriver ());
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Current);
Assert.NotNull (Application.CurrentView);
Assert.NotNull (Application.Top);
@@ -41,7 +41,7 @@ namespace Terminal.Gui {
}
[Fact]
public void TestNewRunState ()
public void RunState_Dispose_Cleans_Up ()
{
var rs = new Application.RunState (null);
Assert.NotNull (rs);
@@ -58,10 +58,10 @@ namespace Terminal.Gui {
}
[Fact]
public void TestBeginEnd ()
public void Begin_End_Cleana_Up ()
{
// Setup Mock driver
Application.Init (new MockDriver ());
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Driver);
// Test null Toplevel
@@ -83,10 +83,10 @@ namespace Terminal.Gui {
}
[Fact]
public void TestRequestStop ()
public void RequestStop_Stops ()
{
// Setup Mock driver
Application.Init (new MockDriver ());
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Driver);
var top = new Toplevel ();
@@ -109,10 +109,10 @@ namespace Terminal.Gui {
}
[Fact]
public void TestRunningFalse ()
public void RunningFalse_Stops ()
{
// Setup Mock driver
Application.Init (new MockDriver ());
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Driver);
var top = new Toplevel ();
@@ -136,10 +136,10 @@ namespace Terminal.Gui {
[Fact]
public void TestKeyUp ()
public void KeyUp_Event ()
{
// Setup Mock driver
Application.Init (new MockDriver ());
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Driver);
// Setup some fake kepresses (This)

View File

@@ -3,14 +3,14 @@ using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.MockConsole;
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui {
public class ConsoleDriverTests {
[Fact]
public void TestInit ()
public void Init_Inits ()
{
var driver = new MockDriver ();
var driver = new FakeDriver ();
driver.Init (() => { });
Assert.Equal (80, Console.BufferWidth);
@@ -23,15 +23,15 @@ namespace Terminal.Gui {
}
[Fact]
public void TestEnd ()
public void End_Cleans_Up ()
{
var driver = new MockDriver ();
var driver = new FakeDriver ();
driver.Init (() => { });
MockConsole.ForegroundColor = ConsoleColor.Red;
FakeConsole.ForegroundColor = ConsoleColor.Red;
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
MockConsole.BackgroundColor = ConsoleColor.Green;
FakeConsole.BackgroundColor = ConsoleColor.Green;
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
driver.Move (2, 3);
Assert.Equal (2, Console.CursorLeft);
@@ -45,9 +45,9 @@ namespace Terminal.Gui {
}
[Fact]
public void TestSetColors ()
public void SetColors_Changes_Colors ()
{
var driver = new MockDriver ();
var driver = new FakeDriver ();
driver.Init (() => { });
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);

122
UnitTests/DimTests.cs Normal file
View File

@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui {
public class DimTests {
[Fact]
public void New_Works ()
{
var dim = new Dim ();
Assert.Equal ("Terminal.Gui.Dim", dim.ToString ());
}
[Fact]
public void Sized_SetsValue ()
{
var dim = Dim.Sized (0);
Assert.Equal ("Dim.Absolute(0)", dim.ToString ());
int testVal = 5;
dim = Dim.Sized (testVal);
Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
}
// TODO: Other Dim.Sized tests (e.g. Equal?)
[Fact]
public void Width_SetsValue ()
{
var dim = Dim.Width (null);
Assert.Throws<NullReferenceException> (() => dim.ToString ());
var testVal = Rect.Empty;
testVal = Rect.Empty;
dim = Dim.Width (new View (testVal));
Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
testVal = new Rect (1, 2, 3, 4);
dim = Dim.Width (new View (testVal));
Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
}
// TODO: Other Dim.Width tests (e.g. Equal?)
[Fact]
public void Height_SetsValue ()
{
var dim = Dim.Height (null);
Assert.Throws<NullReferenceException> (() => dim.ToString ());
var testVal = Rect.Empty;
testVal = Rect.Empty;
dim = Dim.Height (new View (testVal));
Assert.Equal ($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
testVal = new Rect (1, 2, 3, 4);
dim = Dim.Height (new View (testVal));
Assert.Equal ($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
}
// TODO: Other Dim.Height tests (e.g. Equal?)
[Fact]
public void Fill_SetsValue ()
{
var testMargin = 0;
var dim = Dim.Fill ();
Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString());
testMargin = 0;
dim = Dim.Fill (testMargin);
Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
testMargin = 5;
dim = Dim.Fill (testMargin);
Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
}
[Fact]
public void Fill_Equal()
{
var margin1 = 0;
var margin2 = 0;
var dim1 = Dim.Fill (margin1);
var dim2 = Dim.Fill (margin2);
Assert.Equal (dim1, dim2);
}
[Fact]
public void Percent_SetsValue ()
{
var dim = Dim.Percent (0);
Assert.Equal ("Dim.Factor(0)", dim.ToString ());
dim = Dim.Percent (0.5F);
Assert.Equal ("Dim.Factor(0.005)", dim.ToString ());
dim = Dim.Percent (100);
Assert.Equal ("Dim.Factor(1)", dim.ToString ());
}
// TODO: Other Dim.Percent tests (e.g. Equal?)
[Fact]
public void Percent_ThrowsOnIvalid()
{
var dim = Dim.Percent (0);
Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));
Assert.Throws<ArgumentException> (() => dim = Dim.Percent (101));
Assert.Throws<ArgumentException> (() => dim = Dim.Percent (100.0001F));
Assert.Throws<ArgumentException> (() => dim = Dim.Percent (1000001));
}
// TODO: Test operators
}
}

View File

@@ -7,29 +7,47 @@ using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.MockConsole;
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui {
public class DimPosTests {
public class PosTests {
[Fact]
public void TestNew ()
public void New_Works ()
{
var pos = new Pos ();
Assert.Equal ("Terminal.Gui.Pos", pos.ToString ());
}
[Fact]
public void TestAnchorEnd ()
public void AnchorEnd_SetsValue ()
{
var n = 0;
var pos = Pos.AnchorEnd ();
Assert.Equal ("Pos.AnchorEnd(margin=0)", pos.ToString ());
Assert.Equal ($"Pos.AnchorEnd(margin={n})", pos.ToString ());
pos = Pos.AnchorEnd (5);
Assert.Equal ("Pos.AnchorEnd(margin=5)", pos.ToString ());
n = 5;
pos = Pos.AnchorEnd (n);
Assert.Equal ($"Pos.AnchorEnd(margin={n})", pos.ToString ());
}
[Fact]
public void TestAt ()
public void AnchorEnd_Equal ()
{
var n1 = 0;
var n2 = 0;
var pos1 = Pos.AnchorEnd (n1);
var pos2 = Pos.AnchorEnd (n2);
Assert.Equal (pos1, pos2);
// Test inequality
n2 = 5;
pos2 = Pos.AnchorEnd (n2);
Assert.NotEqual (pos1, pos2);
}
[Fact]
public void At_SetsValue ()
{
var pos = Pos.At (0);
Assert.Equal ("Pos.Absolute(0)", pos.ToString ());
@@ -41,79 +59,125 @@ namespace Terminal.Gui {
}
[Fact]
public void TestLeft ()
public void At_Equal ()
{
var n1 = 0;
var n2 = 0;
var pos1 = Pos.At (n1);
var pos2 = Pos.At (n2);
// BUGBUG: Pos should implement equality and this should change to Equal
Assert.NotEqual (pos1, pos2);
}
[Fact]
public void Left_SetsValue ()
{
var pos = Pos.Left (null);
Assert.Throws<NullReferenceException> (() => pos.ToString ());
var testVal = Rect.Empty;
pos = Pos.Left (new View ());
Assert.Equal ("Pos.View(side=x, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
pos = Pos.Left (new View (new Rect (1, 2, 3, 4)));
Assert.Equal ("Pos.View(side=x, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
pos = Pos.Left (new View (testVal));
Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
testVal = new Rect (1, 2, 3, 4);
pos = Pos.Left (new View (testVal));
Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
}
// TODO: Test Left, Top, Right bottom Equal
[Fact]
public void TestTop ()
public void Top_SetsValue ()
{
var pos = Pos.Top (null);
Assert.Throws<NullReferenceException> (() => pos.ToString ());
var testVal = Rect.Empty;
pos = Pos.Top (new View ());
Assert.Equal ("Pos.View(side=y, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
Assert.Equal ($"Pos.View(side=y, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
pos = Pos.Top (new View (new Rect (1, 2, 3, 4)));
Assert.Equal ("Pos.View(side=y, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
testVal = new Rect (1, 2, 3, 4);
pos = Pos.Top (new View (testVal));
Assert.Equal ($"Pos.View(side=y, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
}
[Fact]
public void TestRight ()
public void Right_SetsValue ()
{
var pos = Pos.Right (null);
Assert.Throws<NullReferenceException> (() => pos.ToString ());
var testVal = Rect.Empty;
pos = Pos.Right (new View ());
Assert.Equal ("Pos.View(side=right, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
pos = Pos.Right (new View (new Rect (1, 2, 3, 4)));
Assert.Equal ("Pos.View(side=right, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
testVal = Rect.Empty;
pos = Pos.Right (new View (testVal));
Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
testVal = new Rect (1, 2, 3, 4);
pos = Pos.Right (new View (testVal));
Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
}
[Fact]
public void TestBottom ()
public void Bottom_SetsValue ()
{
var pos = Pos.Bottom (null);
Assert.Throws<NullReferenceException> (() => pos.ToString ());
var testVal = Rect.Empty;
pos = Pos.Bottom (new View ());
Assert.Equal ("Pos.View(side=bottom, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
pos = Pos.Bottom (new View (new Rect (1, 2, 3, 4)));
Assert.Equal ("Pos.View(side=bottom, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
testVal = Rect.Empty;
pos = Pos.Bottom (new View (testVal));
Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
testVal = new Rect (1, 2, 3, 4);
pos = Pos.Bottom (new View (testVal));
Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
//Assert.Throws<ArgumentException> (() => pos = Pos.Bottom (new View (new Rect (0, 0, -3, -4))));
}
[Fact]
public void TestCenter ()
public void Center_SetsValue ()
{
var pos = Pos.Center ();
Assert.Equal ("Pos.Center", pos.ToString ());
}
[Fact]
public void TestPercent ()
public void Percent_SetsValue ()
{
var pos = Pos.Percent (0);
Assert.Equal ("Pos.Factor(0)", pos.ToString ());
pos = Pos.Percent (0.5F);
Assert.Equal ("Pos.Factor(0.005)", pos.ToString ());
pos = Pos.Percent (100);
Assert.Equal ("Pos.Factor(1)", pos.ToString ());
}
[Fact]
public void Percent_Equal ()
{
var n1 = 0;
var n2 = 0;
var pos1 = Pos.Percent (n1);
var pos2 = Pos.Percent (n2);
// BUGBUG: Pos.Percent should support equality
Assert.NotEqual (pos1, pos2);
}
[Fact]
public void Percent_ThrowsOnIvalid ()
{
var pos = Pos.Percent (0);
Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
Assert.Throws<ArgumentException> (() => pos = Pos.Percent (100.0001F));
@@ -121,7 +185,5 @@ namespace Terminal.Gui {
}
// TODO: Test operators
// TODO: Test Dim
}
}

View File

@@ -5,12 +5,12 @@ using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.MockConsole;
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui {
public class ResponderTests {
[Fact]
public void TestNew ()
public void New_Initializes ()
{
var r = new Responder ();
Assert.NotNull (r);
@@ -20,7 +20,7 @@ namespace Terminal.Gui {
}
[Fact]
public void TestMethods ()
public void New_Methods_Return_False ()
{
var r = new Responder ();

View File

@@ -7,12 +7,12 @@ using Terminal.Gui;
using Xunit;
// Alais Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.MockConsole;
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui {
public class ViewTests {
[Fact]
public void TestNew ()
public void New_Initializes ()
{
// Parameterless
var r = new View ();
@@ -90,7 +90,7 @@ namespace Terminal.Gui {
}
[Fact]
public void TestMethods ()
public void New_Methods_Return_False ()
{
var r = new View ();