mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Code cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using static Terminal.Gui.ConfigurationManager;
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
namespace Terminal.Gui.ConfigurationTests;
|
||||
|
||||
@@ -45,65 +46,65 @@ public class ConfigurationManagerTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeepMemberwiseCopyTest ()
|
||||
public void DeepMemberWiseCopyTest ()
|
||||
{
|
||||
// Value types
|
||||
var stringDest = "Destination";
|
||||
var stringSrc = "Source";
|
||||
object stringCopy = DeepMemberwiseCopy (stringSrc, stringDest);
|
||||
object stringCopy = DeepMemberWiseCopy (stringSrc, stringDest);
|
||||
Assert.Equal (stringSrc, stringCopy);
|
||||
|
||||
stringDest = "Destination";
|
||||
stringSrc = "Destination";
|
||||
stringCopy = DeepMemberwiseCopy (stringSrc, stringDest);
|
||||
stringCopy = DeepMemberWiseCopy (stringSrc, stringDest);
|
||||
Assert.Equal (stringSrc, stringCopy);
|
||||
|
||||
stringDest = "Destination";
|
||||
stringSrc = null;
|
||||
stringCopy = DeepMemberwiseCopy (stringSrc, stringDest);
|
||||
stringCopy = DeepMemberWiseCopy (stringSrc, stringDest);
|
||||
Assert.Equal (stringSrc, stringCopy);
|
||||
|
||||
stringDest = "Destination";
|
||||
stringSrc = string.Empty;
|
||||
stringCopy = DeepMemberwiseCopy (stringSrc, stringDest);
|
||||
stringCopy = DeepMemberWiseCopy (stringSrc, stringDest);
|
||||
Assert.Equal (stringSrc, stringCopy);
|
||||
|
||||
var boolDest = true;
|
||||
var boolSrc = false;
|
||||
object boolCopy = DeepMemberwiseCopy (boolSrc, boolDest);
|
||||
object boolCopy = DeepMemberWiseCopy (boolSrc, boolDest);
|
||||
Assert.Equal (boolSrc, boolCopy);
|
||||
|
||||
boolDest = false;
|
||||
boolSrc = true;
|
||||
boolCopy = DeepMemberwiseCopy (boolSrc, boolDest);
|
||||
boolCopy = DeepMemberWiseCopy (boolSrc, boolDest);
|
||||
Assert.Equal (boolSrc, boolCopy);
|
||||
|
||||
boolDest = true;
|
||||
boolSrc = true;
|
||||
boolCopy = DeepMemberwiseCopy (boolSrc, boolDest);
|
||||
boolCopy = DeepMemberWiseCopy (boolSrc, boolDest);
|
||||
Assert.Equal (boolSrc, boolCopy);
|
||||
|
||||
boolDest = false;
|
||||
boolSrc = false;
|
||||
boolCopy = DeepMemberwiseCopy (boolSrc, boolDest);
|
||||
boolCopy = DeepMemberWiseCopy (boolSrc, boolDest);
|
||||
Assert.Equal (boolSrc, boolCopy);
|
||||
|
||||
// Structs
|
||||
var attrDest = new Attribute (Color.Black);
|
||||
var attrSrc = new Attribute (Color.White);
|
||||
object attrCopy = DeepMemberwiseCopy (attrSrc, attrDest);
|
||||
object attrCopy = DeepMemberWiseCopy (attrSrc, attrDest);
|
||||
Assert.Equal (attrSrc, attrCopy);
|
||||
|
||||
// Classes
|
||||
var colorschemeDest = new ColorScheme { Disabled = new Attribute (Color.Black) };
|
||||
var colorschemeSrc = new ColorScheme { Disabled = new Attribute (Color.White) };
|
||||
object colorschemeCopy = DeepMemberwiseCopy (colorschemeSrc, colorschemeDest);
|
||||
object colorschemeCopy = DeepMemberWiseCopy (colorschemeSrc, colorschemeDest);
|
||||
Assert.Equal (colorschemeSrc, colorschemeCopy);
|
||||
|
||||
// Dictionaries
|
||||
Dictionary<string, Attribute> dictDest = new () { { "Disabled", new Attribute (Color.Black) } };
|
||||
Dictionary<string, Attribute> dictSrc = new () { { "Disabled", new Attribute (Color.White) } };
|
||||
Dictionary<string, Attribute> dictCopy = (Dictionary<string, Attribute>)DeepMemberwiseCopy (dictSrc, dictDest);
|
||||
Dictionary<string, Attribute> dictCopy = (Dictionary<string, Attribute>)DeepMemberWiseCopy (dictSrc, dictDest);
|
||||
Assert.Equal (dictSrc, dictCopy);
|
||||
|
||||
dictDest = new Dictionary<string, Attribute> { { "Disabled", new Attribute (Color.Black) } };
|
||||
@@ -112,7 +113,7 @@ public class ConfigurationManagerTests
|
||||
{
|
||||
{ "Disabled", new Attribute (Color.White) }, { "Normal", new Attribute (Color.Blue) }
|
||||
};
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberwiseCopy (dictSrc, dictDest);
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberWiseCopy (dictSrc, dictDest);
|
||||
Assert.Equal (dictSrc, dictCopy);
|
||||
|
||||
// src adds an item
|
||||
@@ -122,7 +123,7 @@ public class ConfigurationManagerTests
|
||||
{
|
||||
{ "Disabled", new Attribute (Color.White) }, { "Normal", new Attribute (Color.Blue) }
|
||||
};
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberwiseCopy (dictSrc, dictDest);
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberWiseCopy (dictSrc, dictDest);
|
||||
Assert.Equal (2, dictCopy.Count);
|
||||
Assert.Equal (dictSrc ["Disabled"], dictCopy ["Disabled"]);
|
||||
Assert.Equal (dictSrc ["Normal"], dictCopy ["Normal"]);
|
||||
@@ -133,7 +134,7 @@ public class ConfigurationManagerTests
|
||||
{ "Disabled", new Attribute (Color.Black) }, { "Normal", new Attribute (Color.White) }
|
||||
};
|
||||
dictSrc = new Dictionary<string, Attribute> { { "Disabled", new Attribute (Color.White) } };
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberwiseCopy (dictSrc, dictDest);
|
||||
dictCopy = (Dictionary<string, Attribute>)DeepMemberWiseCopy (dictSrc, dictDest);
|
||||
Assert.Equal (2, dictCopy.Count);
|
||||
Assert.Equal (dictSrc ["Disabled"], dictCopy ["Disabled"]);
|
||||
Assert.Equal (dictDest ["Normal"], dictCopy ["Normal"]);
|
||||
@@ -379,7 +380,7 @@ public class ConfigurationManagerTests
|
||||
|
||||
Assert.NotEmpty (Settings);
|
||||
|
||||
// test that all ConfigProperites have our attribute
|
||||
// test that all ConfigProperties have our attribute
|
||||
Assert.All (
|
||||
Settings,
|
||||
item => Assert.NotEmpty (
|
||||
@@ -411,7 +412,7 @@ public class ConfigurationManagerTests
|
||||
[Fact]
|
||||
public void TestConfigPropertyOmitClassName ()
|
||||
{
|
||||
// Color.ColorShemes is serialzied as "ColorSchemes", not "Colors.ColorSchemes"
|
||||
// Color.ColorSchemes is serialized as "ColorSchemes", not "Colors.ColorSchemes"
|
||||
PropertyInfo pi = typeof (Colors).GetProperty ("ColorSchemes");
|
||||
var scp = (SerializableConfigurationProperty)pi.GetCustomAttribute (typeof (SerializableConfigurationProperty));
|
||||
Assert.True (scp.Scope == typeof (ThemeScope));
|
||||
@@ -624,7 +625,7 @@ public class ConfigurationManagerTests
|
||||
jsonException = Assert.Throws<JsonException> (() => Settings.Update (json, "test"));
|
||||
Assert.Equal ("Both Foreground and Background colors must be provided.", jsonException.Message);
|
||||
|
||||
// Unknown proeprty
|
||||
// Unknown property
|
||||
json = @"
|
||||
{
|
||||
""Unknown"" : ""Not known""
|
||||
|
||||
Reference in New Issue
Block a user