/// <summary> /// Parses the specified text for configuration entries. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public IList <ConfigLine> Parse(string text) { var results = new List <ConfigLine>(); var lines = text.Split(Environment.NewLine); var section = string.Empty; foreach (var line in lines) { // only process lines if content if (string.IsNullOrWhiteSpace(line)) { continue; } // section header? if (line.StartsWith("[")) { section = line.SubstringAfterChar("[").SubstringBeforeLastChar("]"); continue; } ConfigLine result; if (ConfigLine.TryParse(line, out result, section: section)) { results.Add(result); } } return(results); }
public void TestParseConfigLineWhenAComnentWithInvalidIndicator() { const string input = @"//comment"; ConfigLine line; Assert.Throws <ArgumentException>(() => ConfigLine.TryParse(input, out line, "")); }
public void TestParseConfigLineWithEqualsInValue() { const string input = "test=value=something"; ConfigLine line; ConfigLine.TryParse(input, out line); Assert.AreEqual("value=something", line.Value); }
public void TestParseConfigLineSetSectionName() { const string input = "test=value"; ConfigLine line; ConfigLine.TryParse(input, out line, section: "Main"); Assert.AreEqual("Main", line.Section); }
public void TestParseConfigLineWithNoEqualsInValue() { const string input = "test value is here"; ConfigLine line; ConfigLine.TryParse(input, out line); Assert.AreEqual("test value is here", line.Key); Assert.AreEqual("", line.Value); }
public void TestParseConfigLine() { const string input = "test=value"; ConfigLine line; var result = ConfigLine.TryParse(input, out line); Assert.IsTrue(result); Assert.AreEqual("test", line.Key); Assert.AreEqual("value", line.Value); Assert.IsFalse(line.IsComment); }
public void TestParseConfigLineWhenAComnentWithDifferentIndicator() { const string input = @"//comment"; ConfigLine line; var result = ConfigLine.TryParse(input, out line, @"//"); Assert.IsTrue(result); Assert.AreEqual(string.Empty, line.Key); Assert.AreEqual("comment", line.Value); Assert.IsTrue(line.IsComment); }
public void TestParseConfigLineWhenAComnent() { const string input = "#comment"; ConfigLine line; var result = ConfigLine.TryParse(input, out line); Assert.IsTrue(result); Assert.AreEqual(string.Empty, line.Key); Assert.AreEqual("comment", line.Value); Assert.IsTrue(line.IsComment); }