Esempio n. 1
0
        public void RegularPropTest()
        {
            const string s = "A,B,z\n1,2,3";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader);

            Assert.AreEqual(2, parser.ReadLine().B);
        }
Esempio n. 2
0
        public void CustomTypeNoParserTest()
        {
            const string s = "A,B,z,D\n1,2,3,1 2 3 4";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader);

            Assert.Catch <CSV.ParseException>(() => parser.ReadLine());
        }
Esempio n. 3
0
        public void NoSetterTest()
        {
            const string s = "A,B,z\n1,2,3";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader);

            Assert.AreEqual(0, parser.ReadLine().A);
        }
Esempio n. 4
0
        public void SkipRowsTest()
        {
            const string s = "garbage\nA,B,z\n1,2,3";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader, initiallySkippedRows: 1);

            Assert.AreEqual(3, parser.ReadLine().C);
        }
Esempio n. 5
0
        public void CustomTypeBadParserTest()
        {
            const string s = "A,B,z,D\n1,2,3,1 2 3 4";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader);

            CSV.Parsers.RegisterParser <IEnumerable <int> >(_ => throw new NotImplementedException());

            Assert.Catch <CSV.ParseException>(() => parser.ReadLine());
        }
Esempio n. 6
0
        public void CustomTypeParserTest()
        {
            const string s = "A,B,z,D\n1,2,3,1 2 3 4";

            using var reader = new StringReader(s);
            var parser = new CSV.Parser <Foo>(reader);

            CSV.Parsers.RegisterParser(str => str.Split(" ").Select(CSV.Parsers.Parse <int>));

            var enumerable = (IEnumerable <int>) new List <int> {
                1, 2, 3, 4
            };

            Assert.AreEqual(enumerable, parser.ReadLine().D);
        }
Esempio n. 7
0
        public void AttributeTest()
        {
            const string s = "A,B,z\n1,2,3";

            using (var reader = new StringReader(s))
            {
                var parser = new CSV.Parser <Foo>(reader);
                Assert.AreEqual(3, parser.ReadLine().C);
            }

            const string s2 = "A,B,C\n1,2,3";

            using (var reader = new StringReader(s2))
            {
                var parser2 = new CSV.Parser <Foo>(reader);
                Assert.AreEqual(0, parser2.ReadLine().C);
            }
        }
Esempio n. 8
0
        public void MissingFieldTest()
        {
            const string s = "A,B,z\n1,,3";

            using (var reader = new StringReader(s))
            {
                var parser = new CSV.Parser <Foo>(reader);
                Assert.AreEqual(null, parser.ReadLine().B);
            }

            const string s2 = "A,B,z\n1,2";

            using (var reader = new StringReader(s2))
            {
                var parser2 = new CSV.Parser <Foo>(reader);
                Assert.AreEqual(0, parser2.ReadLine().C);
            }
        }
Esempio n. 9
0
        public void IterationTest()
        {
            const string s = "B,z\n1,2\n4,5";

            using var reader = new StringReader(s);

            var parser = new CSV.Parser <Foo>(reader);

            var list = new List <Foo>
            {
                new Foo {
                    B = 1, C = 2
                },
                new Foo {
                    B = 4, C = 5
                }
            };

            foreach (var(actual, expected) in parser.Zip(list))
            {
                Assert.AreEqual(expected, actual);
            }
        }