Exemplo n.º 1
0
        private static void testXls()
        {
            var xlsParser        = TabularDataParser.CreateForExcelFile(@"..\..\..\TestFiles\TewlTestBook.xlsx");
            var validationErrors = new List <ValidationError>();

            xlsParser.ParseAndProcessAllLines(importThing, validationErrors);

            Console.WriteLine($"Excel test: {xlsParser.RowsWithoutValidationErrors} rows imported without error.");
        }
Exemplo n.º 2
0
        private static void testCsv()
        {
            var csvParser        = TabularDataParser.CreateForCsvFile(@"..\..\..\TestFiles\TewlTestBook.csv", true);
            var validationErrors = new List <ValidationError>();

            csvParser.ParseAndProcessAllLines(importThing, validationErrors);

            Console.WriteLine($"CSV test: {csvParser.RowsWithoutValidationErrors} rows imported without error.");
        }
Exemplo n.º 3
0
        public void TestReadCsvEmptyLines()
        {
            string input = "r1c1,,\r\n" +
                           ",,\r\n" +
                           "r3c1,,";
            var output = new TabularDataParser(TabularDataFormat.CreateCsv()).Read(input);

            Assert.AreEqual("r1c1", output[0][0], "Row 1 column 1");
            Assert.AreEqual(String.Empty, output[0][2], "Row 1 column 3");
            Assert.AreEqual("r3c1", output[2][0], "Row 3 column 1");
        }
Exemplo n.º 4
0
        public void TestWriteCsv()
        {
            string output;
            string expectedOutput = "foo,bar,baz\r\n" +
                                    "wibble,wobble,spong";
            IList <IList <string> > input = new string[][] { new string[] { "foo", "bar", "baz" },
                                                             new string[] { "wibble", "wobble", "spong" } };
            ITabularDataParser parser = new TabularDataParser(TabularDataFormat.CreateCsv());

            output = parser.Write(input);
            Assert.AreEqual(expectedOutput, output, "Correct string rendering");
        }
Exemplo n.º 5
0
        public void TestReadCsv()
        {
            string input = "foo,bar,baz\r\n" +
                           "wibble,wobble,spong";
            ITabularDataParser parser = new TabularDataParser(TabularDataFormat.CreateCsv());

            var output = parser.Read(input);

            Assert.AreEqual(2, output.GetRowCount(), "Correct row count");
            Assert.AreEqual("wibble", output[1][0], "Correct data in second row, first column");
            Assert.AreEqual("wobble", output[1][1], "Correct data in second row, second column");
        }
Exemplo n.º 6
0
        public void TestWriteTsvWithQuotes()
        {
            string output;
            string expectedOutput = "foo\tbar\tbaz\n" +
                                    "wibble\t  wobble  \tspong\n" +
                                    "  foo\t\"bar\"\tbaz,bork";
            IList <IList <string> > input = new string[][] { new string[] { "foo", "bar", "baz" },
                                                             new string[] { "wibble", "  wobble  ", "spong" },
                                                             new string[] { "  foo", "\"bar\"", "baz,bork" } };
            ITabularDataParser parser = new TabularDataParser(TabularDataFormat.CreateTsv());

            output = parser.Write(input);
            Assert.AreEqual(expectedOutput, output, "Correct string rendering");
        }
Exemplo n.º 7
0
        public void TestReadCsvWithQuotedUnicode()
        {
            string input = "foo,bar,baz\r\n" +
                           "wibble,    wobble   ,spong\r\n" +
                           "\"  foo\",\"\"\"bar\"\"\",\"A big, \"\"big, ¥en test!\"";
            ITabularDataParser parser = new TabularDataParser(TabularDataFormat.CreateCsv());

            var output = parser.Read(input);

            Assert.AreEqual(3, output.GetRowCount(), "Correct row count");
            Assert.AreEqual("wobble", output[1][1], "Correct data in second row, second column");
            Assert.AreEqual("  foo", output[2][0], "Correct data in third row, first column");
            Assert.AreEqual("\"bar\"", output[2][1], "Correct data in third row, second column");
            Assert.AreEqual("A big, \"big, ¥en test!", output[2][2], "Correct data in third row, third column");
        }
Exemplo n.º 8
0
        public void TestWriteTsvFrom2DArray()
        {
            string output;
            string expectedOutput = "foo\tbar\tbaz\n" +
                                    "wibble\twobble\tspong";

            string[,] input = new string[, ] {
                { "foo", "bar", "baz" },
                { "wibble", "wobble", "spong" }
            };
            ITabularDataParser parser = new TabularDataParser(TabularDataFormat.CreateTsv());

            output = parser.Write(input);
            Assert.AreEqual(expectedOutput, output, "Correct string rendering");
        }
Exemplo n.º 9
0
        public void TestReadCsvTolerateTrailingLines()
        {
            // Arrange
            string input = "r1c1,,\r\n" +
                           "r3c1,,\r\n" +
                           "\r\n";

            // Act
            var format = TabularDataFormat.CreateCsv(tolerateEmptyRows: true);
            var output = new TabularDataParser(format).Read(input);

            // Assert
            Assert.AreEqual(2, output.GetRowCount(), "Row count");
            Assert.AreEqual(3, output.GetColumnCount(), "Column count");
            Assert.AreEqual("r1c1", output[0][0], "Row 1 column 1");
            Assert.AreEqual("r3c1", output[1][0], "Row 2 column 1");
        }