Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        public void TestParseConfigLineWhenAComnentWithInvalidIndicator()
        {
            const string input = @"//comment";

            ConfigLine line;

            Assert.Throws <ArgumentException>(() => ConfigLine.TryParse(input, out line, ""));
        }
Beispiel #3
0
        public void TestParseConfigLineWithEqualsInValue()
        {
            const string input = "test=value=something";

            ConfigLine line;

            ConfigLine.TryParse(input, out line);

            Assert.AreEqual("value=something", line.Value);
        }
Beispiel #4
0
        public void TestParseConfigLineSetSectionName()
        {
            const string input = "test=value";

            ConfigLine line;

            ConfigLine.TryParse(input, out line, section: "Main");

            Assert.AreEqual("Main", line.Section);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }