Exemple #1
0
 public void OneSimpleValueQuotesTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse("\"42\"");
     Assert.That(parsed.Count(), Is.EqualTo(1));
     Assert.That(parsed[0][0], Is.EqualTo("42"));
 }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 0)
            {
                Console.WriteLine("need two parameters: file name to parse, file name to export");
                return;
            }
            string inputFilePath = "input.txt";
            string exportFilePath = "output.txt";

            if (args.Length == 2)
            {
                inputFilePath = args[0];
                exportFilePath = args[1];
            }

            if (!File.Exists(inputFilePath))
            {
                Console.WriteLine("{0} (input file) doesn't exist", inputFilePath);
            }

            string inputString;
            using (var reader = new StreamReader(inputFilePath))
            {
                inputString = reader.ReadToEnd();
            }
            var parser = new CsvParser();
            IList<IList<string>> parsedValues = parser.Parse(inputString);
            string outputString = parser.PrepForExport(parsedValues);
            using (var writer = new StreamWriter(exportFilePath))
            {
                writer.Write(outputString);
            }
        }
Exemple #3
0
 public void TwoSimpleValuesNoQuotesTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse("24,42");
     Assert.That(parsed[0].Count(), Is.EqualTo(2));
     Assert.That(parsed[0][0], Is.EqualTo("24"));
     Assert.That(parsed[0][1], Is.EqualTo("42"));
 }
Exemple #4
0
 public void TwoCommaValueQuotesTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse("\"4,2\",\"2,4\"");
     Assert.That(parsed[0].Count(), Is.EqualTo(2));
     Assert.That(parsed[0][0], Is.EqualTo("4,2"));
     Assert.That(parsed[0][1], Is.EqualTo("2,4"));
 }
Exemple #5
0
 public void EmptyTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse(string.Empty);
     Assert.That(parsed.Count(), Is.EqualTo(1));
     Assert.That(parsed[0].Count(), Is.EqualTo(1));
     Assert.That(parsed[0][0], Is.EqualTo(string.Empty));
 }
Exemple #6
0
 public void TwoValuesDoubleQuotesNoQuotesTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse("42,\"-\"\"42\"\"-\"");
     Assert.That(parsed[0].Count(), Is.EqualTo(2));
     Assert.That(parsed[0][0], Is.EqualTo("42"));
     Assert.That(parsed[0][1], Is.EqualTo("-\"42\"-"));
 }
Exemple #7
0
 public void WithNewLineTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse("12,34\n56,78");
     Assert.That(parsed.Count(), Is.EqualTo(2));
     Assert.That(parsed[0].Count(), Is.EqualTo(2));
     Assert.That(parsed[1].Count(), Is.EqualTo(2));
     Assert.That(parsed[0][0], Is.EqualTo("12"));
     Assert.That(parsed[0][1], Is.EqualTo("34"));
     Assert.That(parsed[1][0], Is.EqualTo("56"));
     Assert.That(parsed[1][1], Is.EqualTo("78"));
 }
Exemple #8
0
 public void TwoValuesEmptyQuotesNoQuotesTest()
 {
     var parser = new CsvParser();
     var parsed = parser.Parse(",\"\"");
     Assert.That(parsed[0].Count(), Is.EqualTo(2));
     Assert.That(parsed[0][0], Is.EqualTo(string.Empty));
     Assert.That(parsed[0][1], Is.EqualTo(string.Empty));
 }