From 2564e07a589d5baba8e2f066843929df6d71bc84 Mon Sep 17 00:00:00 2001 From: salaros Date: Mon, 13 Aug 2018 09:40:47 +0200 Subject: [PATCH] just code formatting in tests --- tests/ConfigParserTests.cs | 196 ++++++++++++++++++++----------------- 1 file changed, 108 insertions(+), 88 deletions(-) diff --git a/tests/ConfigParserTests.cs b/tests/ConfigParserTests.cs index 6513389..4df8c1b 100644 --- a/tests/ConfigParserTests.cs +++ b/tests/ConfigParserTests.cs @@ -76,23 +76,23 @@ public void RealWorldFilesEqualToString() { var settings = GetSettingsForFile(realConfigFile); var configFile = new ConfigParser(realConfigFile, settings); - var configFileFromDisk =File - .ReadAllText(realConfigFile) - .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") - .TrimEnd('\n'); + var configFileFromDisk = File + .ReadAllText(realConfigFile) + .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") + .TrimEnd('\n'); var configFileText = configFile - .ToString() - .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") - .TrimEnd('\n'); + .ToString() + .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") + .TrimEnd('\n'); Assert.Equal(configFileText, configFileFromDisk); var tempConfigFilePath = Path.GetTempFileName(); configFile.Save(tempConfigFilePath); configFileFromDisk = File - .ReadAllText(tempConfigFilePath) - .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") - .TrimEnd('\n'); + .ReadAllText(tempConfigFilePath) + .Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\n") + .TrimEnd('\n'); Assert.Equal(configFileText, configFileFromDisk); }); @@ -104,7 +104,8 @@ public void RealWorldFilesEqualToString() [Fact] public void ArrayValuesAreParsedCorrectly() { - var arraySampleFilePath = ValuesSampleFiles.FirstOrDefault(f => f.EndsWith("array.cnf", StringComparison.OrdinalIgnoreCase)); + var arraySampleFilePath = + ValuesSampleFiles.FirstOrDefault(f => f.EndsWith("array.cnf", StringComparison.OrdinalIgnoreCase)); Assert.NotNull(arraySampleFilePath); var configFile = new ConfigParser(arraySampleFilePath, new ConfigParserSettings @@ -122,7 +123,7 @@ public void ArrayValuesAreParsedCorrectly() "PULLREQ_EDITMSG$", "MERGE_MSG$", }; - var excludeArrayFromFile = configFile.GetValue("settings", "exclude", new string[] {}); + var excludeArrayFromFile = configFile.GetValue("settings", "exclude", new string[] { }); Assert.Equal(excludeArrayFromFile, excludeArray); } @@ -132,7 +133,9 @@ public void ArrayValuesAreParsedCorrectly() [Fact] public void IndentedFilesAreParsedCorrectly() { - var indentedFilePath = StructureSampleFiles.FirstOrDefault(f => f.EndsWith("indented.ini", StringComparison.OrdinalIgnoreCase)); + var indentedFilePath = + StructureSampleFiles.FirstOrDefault(f => + f.EndsWith("indented.ini", StringComparison.OrdinalIgnoreCase)); Assert.NotNull(indentedFilePath); var configFile = new ConfigParser(indentedFilePath, new ConfigParserSettings @@ -180,7 +183,7 @@ public void IndentedFilesAreParsedCorrectly() [Fact] public void MultilineValuesAreParsedCorrectly() { - var multiLineDelimitedFilePath = StructureSampleFiles.FirstOrDefault(f => + var multiLineDelimitedFilePath = StructureSampleFiles.FirstOrDefault(f => f.EndsWith("multi-line.ini", StringComparison.OrdinalIgnoreCase)); Assert.NotNull(multiLineDelimitedFilePath); @@ -240,8 +243,8 @@ public void MultilineValuesAreNotAllowed() }); Assert.True( - new [] { "Multi-line values", "disallowed" } - .All(s => multiLineException.Message?.Contains(s, StringComparison.InvariantCulture) ?? false) + new[] {"Multi-line values", "disallowed"} + .All(s => multiLineException.Message?.Contains(s, StringComparison.InvariantCulture) ?? false) ); } @@ -251,14 +254,17 @@ public void MultilineValuesAreNotAllowed() [Fact] public void IndexAccessWorks() { - var indentedFilePath = StructureSampleFiles.FirstOrDefault(f => f.EndsWith("indented.ini", StringComparison.OrdinalIgnoreCase)); + var indentedFilePath = + StructureSampleFiles.FirstOrDefault(f => + f.EndsWith("indented.ini", StringComparison.OrdinalIgnoreCase)); Assert.NotNull(indentedFilePath); var configFile = new ConfigParser(indentedFilePath, new ConfigParserSettings { MultiLineValues = MultiLineValues.Simple }); - var valueReadUsingIndexing = configFile["Sections Can Be Indented"]["can_values_be_as_well"] ?? string.Empty; + var valueReadUsingIndexing = + configFile["Sections Can Be Indented"]["can_values_be_as_well"] ?? string.Empty; Assert.Equal( "True", valueReadUsingIndexing @@ -286,47 +292,47 @@ public void BooleanValuesAreParsedCorrectly() } ); - const string valoriItaliani = "ValoriItaliani"; // [ValoriItaliani] - Assert.True(configFileEnglish.GetValue(valoriItaliani, "positivo", false)); // positivo = vero - Assert.False(configFileEnglish.GetValue(valoriItaliani, "sampleOff", true)); // sampleOff = falso + const string valoriItaliani = "ValoriItaliani"; // [ValoriItaliani] + Assert.True(configFileEnglish.GetValue(valoriItaliani, "positivo", false)); // positivo = vero + Assert.False(configFileEnglish.GetValue(valoriItaliani, "sampleOff", true)); // sampleOff = falso - const string simpleSection = "Simple"; // [Simple] - Assert.False(configFileEnglish.GetValue(simpleSection, "empty", false)); // empty= - Assert.True(configFileEnglish.GetValue(simpleSection, "numericTrue", false)); // numericTrue=1 - Assert.False(configFileEnglish.GetValue(simpleSection, "numericFalse", true)); // numericFalse=0 - Assert.True(configFileEnglish.GetValue(simpleSection, "textTrue", false)); // textTrue = true - Assert.False(configFileEnglish.GetValue(simpleSection, "textFalse", true)); // textFalse = false + const string simpleSection = "Simple"; // [Simple] + Assert.False(configFileEnglish.GetValue(simpleSection, "empty", false)); // empty= + Assert.True(configFileEnglish.GetValue(simpleSection, "numericTrue", false)); // numericTrue=1 + Assert.False(configFileEnglish.GetValue(simpleSection, "numericFalse", true)); // numericFalse=0 + Assert.True(configFileEnglish.GetValue(simpleSection, "textTrue", false)); // textTrue = true + Assert.False(configFileEnglish.GetValue(simpleSection, "textFalse", true)); // textFalse = false // ReSharper disable once RedundantArgumentDefaultValue var yesNoConverter = new YesNoConverter( "yes", // ReSharper disable once RedundantArgumentDefaultValue "no" ); - const string yesNoSection = "YesNo"; // [YesNo] - Assert.True(configFileEnglish.GetValue(yesNoSection, "sampleYes", false, yesNoConverter)); // sampleYes=Yes - Assert.False(configFileEnglish.GetValue(yesNoSection, "sampleNo", true, yesNoConverter)); // sampleNo=no + const string yesNoSection = "YesNo"; // [YesNo] + Assert.True(configFileEnglish.GetValue(yesNoSection, "sampleYes", false, yesNoConverter)); // sampleYes=Yes + Assert.False(configFileEnglish.GetValue(yesNoSection, "sampleNo", true, yesNoConverter)); // sampleNo=no var onOffConverter = new YesNoConverter("on", "off"); - const string onOffSection = "OnOff"; // [OnOff] - Assert.True(configFileEnglish.GetValue(onOffSection, "sampleOn", false, onOffConverter)); // sampleOn=on - Assert.False(configFileEnglish.GetValue(onOffSection, "sampleOff", true, onOffConverter)); // sampleOff=Off + const string onOffSection = "OnOff"; // [OnOff] + Assert.True(configFileEnglish.GetValue(onOffSection, "sampleOn", false, onOffConverter)); // sampleOn=on + Assert.False(configFileEnglish.GetValue(onOffSection, "sampleOff", true, onOffConverter)); // sampleOff=Off var enDisConverter = new YesNoConverter("Enabled", "Disabled"); - const string enDisSection = "EnabledDisabled"; // [EnabledDisabled] - Assert.True(configFileEnglish.GetValue(enDisSection, "sampleOn", false, enDisConverter)); // sampleOn=on - Assert.False(configFileEnglish.GetValue(enDisSection, "sampleOff", true, enDisConverter)); // sampleOff=Off + const string enDisSection = "EnabledDisabled"; // [EnabledDisabled] + Assert.True(configFileEnglish.GetValue(enDisSection, "sampleOn", false, enDisConverter)); // sampleOn=on + Assert.False(configFileEnglish.GetValue(enDisSection, "sampleOff", true, enDisConverter)); // sampleOff=Off // ========================================================================================= // +++++++++ Wow, boolean values parsed auto-magically: look mum no converters +++++++++ // =========================================================================================// [YesNo] - Assert.True(configFileEnglish.GetValue(yesNoSection, "sampleYes", false)); // sampleYes=Yes - Assert.False(configFileEnglish.GetValue(yesNoSection, "sampleNo", true)); // sampleNo=no + Assert.True(configFileEnglish.GetValue(yesNoSection, "sampleYes", false)); // sampleYes=Yes + Assert.False(configFileEnglish.GetValue(yesNoSection, "sampleNo", true)); // sampleNo=no // // [OnOff] - Assert.True(configFileEnglish.GetValue(onOffSection, "sampleOn", false)); // sampleOn=on - Assert.False(configFileEnglish.GetValue(onOffSection, "sampleOff", true)); // sampleOff=Off + Assert.True(configFileEnglish.GetValue(onOffSection, "sampleOn", false)); // sampleOn=on + Assert.False(configFileEnglish.GetValue(onOffSection, "sampleOff", true)); // sampleOff=Off // // [EnabledDisabled] - Assert.True(configFileEnglish.GetValue(enDisSection, "sampleOn", false)); // sampleOn=on - Assert.False(configFileEnglish.GetValue(enDisSection, "sampleOff", true)); // sampleOff=Off + Assert.True(configFileEnglish.GetValue(enDisSection, "sampleOn", false)); // sampleOn=on + Assert.False(configFileEnglish.GetValue(enDisSection, "sampleOff", true)); // sampleOff=Off } /// @@ -340,22 +346,23 @@ public void BooleanValuesAreWrittenCorrectly() // Test "normal" and auto-magic set value const string yesNoSection = "YesNo", sampleYes = "sampleYesNo"; - configFileEnglish.SetValue(yesNoSection, sampleYes, true, new YesNoConverter()); // set to "yes" - Assert.True(configFileEnglish.GetValue(yesNoSection, sampleYes, false)); // check if gets true ("yes") + configFileEnglish.SetValue(yesNoSection, sampleYes, true, new YesNoConverter()); // set to "yes" + Assert.True(configFileEnglish.GetValue(yesNoSection, sampleYes, false)); // check if gets true ("yes") - configFileEnglish.SetValue(yesNoSection, sampleYes, false); // set to false ("no") - Assert.Equal("no", configFileEnglish.GetValue(yesNoSection, sampleYes, "yes")); // check if gets "no" (false) - Assert.False(configFileEnglish.GetValue(yesNoSection, sampleYes, true)); // check if gets false ("no") + configFileEnglish.SetValue(yesNoSection, sampleYes, false); // set to false ("no") + Assert.Equal("no", + configFileEnglish.GetValue(yesNoSection, sampleYes, "yes")); // check if gets "no" (false) + Assert.False(configFileEnglish.GetValue(yesNoSection, sampleYes, true)); // check if gets false ("no") // Test "normal" and auto-magic set value const string intSection = "Integer", sampleInt = "sample0and1"; configFileEnglish.SetValue(intSection, sampleInt, false, new YesNoConverter("1", "0")); // set to "1" - Assert.False(configFileEnglish.GetValue(intSection, sampleInt, true)); // check if gets true ("1") + Assert.False(configFileEnglish.GetValue(intSection, sampleInt, true)); // check if gets true ("1") - configFileEnglish.SetValue(intSection, sampleInt, true); // set to true ("1") - Assert.Equal("1", configFileEnglish.GetValue(intSection, sampleInt, "0")); // check if gets "1" (true) - Assert.True(configFileEnglish.GetValue(intSection, sampleInt, false)); // check if gets true ("1") + configFileEnglish.SetValue(intSection, sampleInt, true); // set to true ("1") + Assert.Equal("1", configFileEnglish.GetValue(intSection, sampleInt, "0")); // check if gets "1" (true) + Assert.True(configFileEnglish.GetValue(intSection, sampleInt, false)); // check if gets true ("1") } /// @@ -373,25 +380,27 @@ public void DoubleValuesAreParsedCorrectly() Culture = new CultureInfo("en-US") }); - const string worksSection = "Works"; // [Works] - Assert.Equal(0D, configFileUsEnglish.GetValue(worksSection, "empty", 0D)); // empty= - Assert.Equal(1.0, configFileUsEnglish.GetValue(worksSection, "integer", 0D)); // integer=1 - Assert.Equal(1E-06, configFileUsEnglish.GetValue(worksSection, "usual", 0D)); // usual=0.000001 - Assert.Equal(6E-01, configFileUsEnglish.GetValue(worksSection, "withD", 0D)); // withD=0.6D - Assert.Equal(1700D, configFileUsEnglish.GetValue(worksSection, "engineeringNotation", 0D)); // engineeringNotation = 1.7E+3 - Assert.Equal(45E-01, configFileUsEnglish.GetValue(worksSection, "float", 0D)); // float = 4.5f - Assert.Equal(1000D, configFileUsEnglish.GetValue(worksSection, "thousands", 0D)); // thousands=1,000 - Assert.Equal(2999D, configFileUsEnglish.GetValue(worksSection, "dollars", 0D, // dollars=$2,999 + const string worksSection = "Works"; // [Works] + Assert.Equal(0D, configFileUsEnglish.GetValue(worksSection, "empty", 0D)); // empty= + Assert.Equal(1.0, configFileUsEnglish.GetValue(worksSection, "integer", 0D)); // integer=1 + Assert.Equal(1E-06, configFileUsEnglish.GetValue(worksSection, "usual", 0D)); // usual=0.000001 + Assert.Equal(6E-01, configFileUsEnglish.GetValue(worksSection, "withD", 0D)); // withD=0.6D + Assert.Equal(1700D, + configFileUsEnglish.GetValue(worksSection, "engineeringNotation", 0D)); // engineeringNotation = 1.7E+3 + Assert.Equal(45E-01, configFileUsEnglish.GetValue(worksSection, "float", 0D)); // float = 4.5f + Assert.Equal(1000D, configFileUsEnglish.GetValue(worksSection, "thousands", 0D)); // thousands=1,000 + Assert.Equal(2999D, configFileUsEnglish.GetValue(worksSection, "dollars", 0D, // dollars=$2,999 NumberStyles.AllowCurrencySymbol)); Assert.Throws(() => - { // [DoesntWork] - Assert.Equal(0D, configFileUsEnglish.GetValue("DoesntWork", "random", 0D)); // random = sdgfery56d + { + // [DoesntWork] + Assert.Equal(0D, configFileUsEnglish.GetValue("DoesntWork", "random", 0D)); // random = sdgfery56d }); var configFileItalian = new ConfigParser(booleanValues, new ConfigParserSettings - { Culture = new CultureInfo("it-IT") }); // [ItalianLocalized] - Assert.Equal(9.3D, configFileItalian.GetValue("ItalianLocalized", "withComa", 0D)); // withComa = 9,3 + {Culture = new CultureInfo("it-IT")}); // [ItalianLocalized] + Assert.Equal(9.3D, configFileItalian.GetValue("ItalianLocalized", "withComa", 0D)); // withComa = 9,3 } /// @@ -401,32 +410,37 @@ public void DoubleValuesAreParsedCorrectly() public void EncodingSettingWorksCorrectly() { // All kinds of UTF* work - Assert.All(EncodingSampleFiles.Where(f => Path.GetFileName(f).StartsWith("UTF", StringComparison.InvariantCultureIgnoreCase)), encodingSampleFile => - { - var settings = GetSettingsForFile(encodingSampleFile); - var encodingConfigFile = new ConfigParser(encodingSampleFile, settings); + Assert.All( + EncodingSampleFiles.Where(f => + Path.GetFileName(f).StartsWith("UTF", StringComparison.InvariantCultureIgnoreCase)), + encodingSampleFile => + { + var settings = GetSettingsForFile(encodingSampleFile); + var encodingConfigFile = new ConfigParser(encodingSampleFile, settings); - Assert.Equal("국민경제의 발전을 위한 중요정책의 수립에 관하여 대통령의 자문에 응하기 위하여 국민경제자문회의를 둘 수 있다.", - encodingConfigFile["LoremIpsum"]["한국어"]); + Assert.Equal("국민경제의 발전을 위한 중요정책의 수립에 관하여 대통령의 자문에 응하기 위하여 국민경제자문회의를 둘 수 있다.", + encodingConfigFile["LoremIpsum"]["한국어"]); - Assert.Equal("είναι απλά ένα κείμενο χωρίς νόημα για τους επαγγελματίες της τυπογραφίας και στοιχειοθεσίας", - encodingConfigFile["LoremIpsum"]["Ελληνικά"]); + Assert.Equal( + "είναι απλά ένα κείμενο χωρίς νόημα για τους επαγγελματίες της τυπογραφίας και στοιχειοθεσίας", + encodingConfigFile["LoremIpsum"]["Ελληνικά"]); - Assert.Equal("也称乱数假文或者哑元文本, 是印刷及排版领域所常用的虚拟文字。", - encodingConfigFile["LoremIpsum"]["中文"]); + Assert.Equal("也称乱数假文或者哑元文本, 是印刷及排版领域所常用的虚拟文字。", + encodingConfigFile["LoremIpsum"]["中文"]); - Assert.Equal("旅ロ京青利セムレ弱改フヨス波府かばぼ意送でぼ調掲察たス日西重ケアナ住橋ユムミク順待ふかんぼ人奨貯鏡すびそ。", - encodingConfigFile["LoremIpsum"]["日本語"]); + Assert.Equal("旅ロ京青利セムレ弱改フヨス波府かばぼ意送でぼ調掲察たス日西重ケアナ住橋ユムミク順待ふかんぼ人奨貯鏡すびそ。", + encodingConfigFile["LoremIpsum"]["日本語"]); - Assert.Equal("छपाई और अक्षर योजना उद्योग का एक साधारण डमी पाठ है", - encodingConfigFile["LoremIpsum"]["हिंदी"]); + Assert.Equal("छपाई और अक्षर योजना उद्योग का एक साधारण डमी पाठ है", + encodingConfigFile["LoremIpsum"]["हिंदी"]); - Assert.Equal("זוהי עובדה מבוססת שדעתו של הקורא תהיה מוסחת על ידי טקטס קריא כאשר הוא יביט בפריסתו", - encodingConfigFile["LoremIpsum"]["אנגלית"]); + Assert.Equal("זוהי עובדה מבוססת שדעתו של הקורא תהיה מוסחת על ידי טקטס קריא כאשר הוא יביט בפריסתו", + encodingConfigFile["LoremIpsum"]["אנגלית"]); - Assert.Equal("Lorem ipsum – псевдо-латинский текст, который используется для веб дизайна, типографии", - encodingConfigFile["LoremIpsum"]["Русский"]); - }); + Assert.Equal( + "Lorem ipsum – псевдо-латинский текст, который используется для веб дизайна, типографии", + encodingConfigFile["LoremIpsum"]["Русский"]); + }); // ANSI Cyrillic - works var ansiCyrillicFilePath = EncodingSampleFiles.FirstOrDefault(f => @@ -504,7 +518,7 @@ private static ConfigParserSettings GetSettingsForFile(string pathToConfigFile) ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } - catch(Exception ex) + catch (Exception ex) { Debug.Assert(null == ex.Message); return null; @@ -521,7 +535,12 @@ public void NonExistingFileWorks() try { var notExistingFilePath = $"{Path.GetTempFileName()}.conf"; - configFileFromMem = new ConfigParser(notExistingFilePath); + configFileFromMem = new ConfigParser(notExistingFilePath, new ConfigParserSettings + { + MultiLineValues = MultiLineValues.Simple | MultiLineValues.QuoteDelimitedValues, + Encoding = new UTF8Encoding(false, false), + NewLine = "\n" + }); } finally { @@ -586,9 +605,10 @@ public void ParsingConfigFileStringWorks() valueLessKey", new ConfigParserSettings { - MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | MultiLineValues.QuoteDelimitedValues, + MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | + MultiLineValues.QuoteDelimitedValues, Culture = new CultureInfo("en-US"), - + } ); @@ -616,7 +636,7 @@ public void ParsingConfigFileStringWorks() Assert.True(configFileFromString.GetValue("boolean", "worksAsWell", false)); // ["arrayElement1","arrayElement2"] - Assert.Equal(new[] { "arrayElement1", "arrayElement2" }, + Assert.Equal(new[] {"arrayElement1", "arrayElement2"}, configFileFromString.GetArrayValue("Advanced", "arrayWorkToo")); // null