public void Initialization() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); section.Add(new Ini.Setting() { Name = "Key" }); // empty value var lines = config.GetLines(); foreach (var line in lines) { Debug.WriteLine(line); } Assert.AreEqual(3, lines.Length); Assert.AreEqual("[Test]\n", lines[0]); Assert.AreEqual(2, config.Changes); }
public void GetSetDefaultGetOnly() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); string SettingName = "Preset"; string SettingName2 = "ArrayPreset"; int oldVal = 5; int newVal = 7; section[SettingName].Int = oldVal; int mods = config.Changes; var setting = section.GetOrSet(SettingName, newVal); Assert.AreEqual(mods, config.Changes); Assert.AreEqual(oldVal, setting.Int); section[SettingName2].IntArray = new int[] { 1, 2, 3 }; mods = config.Changes; var setting2 = section.GetOrSet(SettingName2, new int[] { 7, 8, 9 }); Assert.AreEqual(mods, config.Changes); // no changes var array = setting2.IntArray; Assert.AreEqual(1, array[0]); Assert.AreEqual(2, array[1]); Assert.AreEqual(3, array[2]); Assert.AreEqual("{ 1, 2, 3 }", new ExposedSetting(setting2).ExposedEscapedValue); }
public void GetSetDefaultDoesSet() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); int newVal = 5; int mods = config.Changes; var setVal = section.GetOrSet("NotSet", newVal); Assert.AreEqual(mods + 2, config.Changes); Assert.AreEqual(newVal, setVal.Int); var setVal2 = section.GetOrSet("NotSetArray", new int[] { 1, 2, 3 }); Assert.AreEqual(mods + 4, config.Changes); var array = setVal2.IntArray; Assert.AreEqual(1, array[0]); Assert.AreEqual(2, array[1]); Assert.AreEqual(3, array[2]); Assert.AreEqual("{ 1, 2, 3 }", new ExposedSetting(setVal2).ExposedEscapedValue); Assert.AreEqual(5, config.Changes); }
public void SectionEnumerator() { var config = new Ini.Config(); config.Add(new Ini.Section("Test1", 5)); config.Add(new Ini.Section("Test2", 72)); var results = new List <string>(); var resultsInt = new List <int>(); foreach (Ini.Section section in config) { results.Add(section.Name); resultsInt.Add(section.Index); } Assert.AreEqual("Test1", results[0]); Assert.AreEqual(5, resultsInt[0]); Assert.AreEqual("Test2", results[1]); Assert.AreEqual(72, resultsInt[1]); }
public void NameChange() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); var setting = new Ini.Setting() { Name = "Name" }; section.Add(setting); int mods = config.Changes; section.Name = "tseT"; Assert.AreEqual(mods + 1, config.Changes); setting.Name = "emaN"; Assert.AreEqual(mods + 2, config.Changes); }
public void RecursiveSaveAndLoad(int repeats) { if (repeats < 2) { repeats = 2; } if (repeats > 30) { repeats = 30; } var config = new Ini.Config(); var section1Name = "Number Tests"; var section2Name = "String Tests"; var section1Var1Name = "IntArray"; var section1Var2Name = "DoubleValue"; var section2Var1Name = "StringArray"; var section2Var2Name = "String"; var s1var1value = new int[] { 1, 2, 3 }; var s1var1valueEscaped = "{ 1, 2, 3 }"; var s1var2value = 0.5d; var s1var2valueFormatted = "0.5"; var s2var1value = new string[] { "abc", "xyz" }; var s2var1valueEscaped = "{ abc, xyz }"; var s2var2value = "Bad\"#"; var s2var2valueEscaped = "\"Bad\\\"#\""; var section1 = new Ini.Section(section1Name); section1.Add(new Ini.Setting() { Name = section1Var1Name, IntArray = s1var1value }); section1.Add(new Ini.Setting() { Name = section1Var2Name, Double = s1var2value }); config.Add(section1); var section2 = new Ini.Section(section2Name); section2.Add(new Ini.Setting() { Name = section2Var1Name, Array = s2var1value }); section2.Add(new Ini.Setting() { Name = section2Var2Name, Value = s2var2value }); config.Add(section2); const string incrName = "Incrementor"; const string rollName = "Roller"; var section3 = new Section(incrName); section3.Add(new Setting() { Name = rollName, Int = 0 }); config.Add(section3); var data = config.GetLines(); for (int i = 0; i < repeats; i++) { config = Ini.Config.FromData(data); // read written config Assert.AreEqual(3, config.ItemCount); var s1 = config.Get(section1Name); var s2 = config.Get(section2Name); Assert.IsNotNull(s1); Assert.IsNotNull(s2); var s1v1 = s1.Get(section1Var1Name); var s1v2 = s1.Get(section1Var2Name); var s2v1 = s2.Get(section2Var1Name); var s2v2 = s2.Get(section2Var2Name); Assert.IsNotNull(s1v1); Assert.IsNotNull(s1v2); Assert.IsNotNull(s2v1); Assert.IsNotNull(s2v2); Assert.AreEqual(s1var1valueEscaped, new ExposedSetting(s1v1).ExposedEscapedValue); Assert.AreEqual(s1var2valueFormatted, s1v2.Value); Assert.AreEqual(s2var1valueEscaped, new ExposedSetting(s2v1).ExposedEscapedValue); Assert.AreEqual(s2var2valueEscaped, new ExposedSetting(s2v2).ExposedEscapedValue); int num = config[incrName][rollName].Int; Assert.AreEqual(i, num); config[incrName][rollName].Int = num + 1; data = config.GetLines(); // re-write config } }