Esempio n. 1
0
 public void DelimitersCannotBeNull()
 {
     using (StringReader reader = new StringReader(string.Empty))
     {
         using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
         {
             parser.SetDelimiters(null);
         }
     }
 }
Esempio n. 2
0
        public void MultipleDelimiters()
        {
            string text = "a bb\tccc\tdddd";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(' ', '\t');
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 3
0
        public void CanSqueezeDelimiters()
        {
            string text = "a  bb  ccc  dddd";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(' ');
                    parser.SqueezeDelimiters = true;
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 4
0
        public void CanParseMultipleFields()
        {
            string newLine = "\r\n";
            string text    = "a;bb;ccc;dddd" + newLine + "111;22;3";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(';');
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                    Assert.AreEqual("111:22:3", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 5
0
        public void CanHandleUnixStyleNewLine()
        {
            string newLine = "\n";
            string text    = "a;bb;ccc;dddd" + newLine + "e;ff;ggg;hhhh";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(';');
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                    Assert.AreEqual("e:ff:ggg:hhhh", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 6
0
        public void DelimitersTest()
        {
            using (StringReader reader = new StringReader(string.Empty))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    char[] delimiters = { ',', ';' };
                    parser.SetDelimiters(delimiters);

                    delimiters[0] = '\t';

                    Assert.AreNotEqual('\t', parser.GetDelimiters()[0]);
                }
            }
        }
Esempio n. 7
0
        public void CanTrimWhiteSpace()
        {
            string newLine = "\r\n";
            string text    = "a;bb ; ccc; dddd " + newLine;

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(';');
                    parser.TrimWhiteSpace = true;
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 8
0
        public void CanSkipCommentedLines()
        {
            string newLine = "\r\n";
            string text    = "#Comment line" + newLine + "a;bb;ccc;dddd";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.SetDelimiters(';');
                    parser.SetCommentTokens("#");
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                }
            }
        }
Esempio n. 9
0
        public void CanReadFromFile()
        {
            string textFile = Path.GetTempFileName();

            try
            {
                using (StreamWriter writer = new StreamWriter(textFile, false))
                {
                    writer.WriteLine("a,bb,ccc,dddd");
                }

                using (DelimitedFieldParser parser = new DelimitedFieldParser(textFile))
                {
                    parser.SetDelimiters(',');
                    Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":"));
                }
            }
            finally
            {
                File.Delete(textFile);
            }
        }