public void TestInvalidUnit() { using (var reader = new StringReader("invalid")) using (var parser = new Parser.Parser(reader, IniOptions.Default)) using (var doc = new ParsedSectionCollection(parser, IniOptions.Default)) { Assert.Throws <InvalidUnitException>(() => doc.GetDefaultSection()); } }
public void TestDontParseDefaultSection() { using (var reader = new StringReader($"[{Section.DefaultSectionName}]")) using (var parser = new Parser.Parser(reader, IniOptions.Default)) using (var doc = new ParsedSectionCollection(parser, IniOptions.Default)) { Assert.Throws <InvalidTokenException>(() => doc.GetDefaultSection()); } }
public void TestGetNonexistentSection() { using (var reader = new StringReader("[section]")) using (var parser = new Parser.Parser(reader, IniOptions.Default)) using (var doc = new ParsedSectionCollection(parser, IniOptions.Default)) { Assert.Throws <ArgumentException>(() => doc.GetSection("nonexistent")); } }
public void GetSectionCaseInsensitiveParsing() { var options = new IniOptions(caseSensitive: false); using (var reader = new StringReader("[SECTION]")) using (var parser = new Parser.Parser(reader, options)) using (var doc = new ParsedSectionCollection(parser, options)) { Assert.NotNull(doc.GetSection("section")); } }
public void GetSectionCaseSensitiveParsing() { var options = new IniOptions(caseSensitive: true); using (var reader = new StringReader("[SECTION]")) using (var parser = new Parser.Parser(reader, options)) using (var doc = new ParsedSectionCollection(parser, options)) { Assert.Throws <ArgumentException>(() => doc.GetSection("section")); } }
public void TestGetSection() { using (var reader = new StringReader("[section1]\n[section2]\n[section3]")) using (var parser = new Parser.Parser(reader, IniOptions.Default)) using (var doc = new ParsedSectionCollection(parser, IniOptions.Default)) { for (var i = 0; i < 3; i++) { var name = $"section{i + 1}"; var section = doc.GetSection(name); Assert.AreEqual(name, section.Name); } } }
public void TestGetSectionsWithProperties() { using (var reader = new StringReader("[section1]\nvalue=10\n[section2]\nvalue=10\n[section3]\nvalue=10")) using (var parser = new Parser.Parser(reader, IniOptions.Default)) using (var doc = new ParsedSectionCollection(parser, IniOptions.Default)) { for (var i = 0; i < 3; i++) { var name = $"section{i + 1}"; var section = doc.GetSection(name); Assert.AreEqual(name, section.Name); Assert.AreEqual(1, section.GetProperties().Count()); Assert.AreEqual(true, section.HasProperty("value")); Assert.AreEqual(10L, section.GetProperty("value").GetValueAs <long>()); } } }
/// <summary> /// Creates a new configuration file reader /// </summary> /// <param name="filename">Path to a configuration file</param> /// <param name="options">Options to use when reading</param> public IniReader(string filename, IniOptions options) { sections = new ParsedSectionCollection(Parser.Parser.FromFile(filename, options), options); }