示例#1
0
 public void Can_recognize_header()
 {
     var parsed = new BlockEx(D_header)
         .Match(file_content.Skip(4).Take(1).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new string[0][])));
     Assert.That(parsed.Success);
 }
示例#2
0
        public void Can_recognize_header()
        {
            var parsed = new BlockEx(D_header)
                         .Match(file_content.Skip(4).Take(1).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new string[0][])));
        }
示例#3
0
        public void Can_parse_several_matches()
        {
            var section = ParseCsv(@";H
            D1;
            D2;
            ;D3
            ;
            ;H
            D4;
            D5;
            ;D6
            ;");

            var blockEx = new BlockEx(@"
                            _   ""H"" : header
                            @V   _ : row+
                            _   @V : row+
                            _   _");
            var ms = blockEx.Matches(section);
            Assert.That(ms.Length, Is.EqualTo(2));
            Assert.That(ToValueTuples(ms[0]), Is.EquivalentTo(ToTuples(
                new[] { new[] { "V", "D1" }, new[] { "V", "D2" }, new[] { "V", "D3" } })));

            Assert.That(ToValueTuples(ms[1]), Is.EquivalentTo(ToTuples(
                new[] { new[] { "V", "D4" }, new[] { "V", "D5" }, new[] { "V", "D6" } })));
        }
 public void Can_extract_information_from_second_block()
 {
     var parsed = new BlockEx(type2)
         .Match(file_content.Skip(10).Take(6).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(
         ToTuples(expected_2)));
 }
示例#5
0
        public void Can_parse_several_matches()
        {
            var section = ParseCsv(@";H
D1;
D2;
;D3
;
;H
D4;
D5;
;D6
;");

            var blockEx = new BlockEx(@"
                            _   ""H"" : header 
                            @V   _ : row+
                            _   @V : row+
                            _   _");
            var ms      = blockEx.Matches(section);

            Assert.That(ms.Length, Is.EqualTo(2));
            Assert.That(ToValueTuples(ms[0]), Is.EquivalentTo(ToTuples(
                                                                  new[] { new[] { "V", "D1" }, new[] { "V", "D2" }, new[] { "V", "D3" } })));

            Assert.That(ToValueTuples(ms[1]), Is.EquivalentTo(ToTuples(
                                                                  new[] { new[] { "V", "D4" }, new[] { "V", "D5" }, new[] { "V", "D6" } })));
        }
示例#6
0
 public void Can_recognize_title()
 {
     var parsed = new BlockEx(A_Report_Title)
         .Match(file_content.Take(1).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(
         new[] { new[] { "Time", "16/09/15 16:17" }, new[] { "Page", "Page: 1" } })));
 }
示例#7
0
        public void Can_recognize_title()
        {
            var parsed = new BlockEx(A_Report_Title)
                         .Match(file_content.Take(1).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(
                                                                   new[] { new[] { "Time", "16/09/15 16:17" }, new[] { "Page", "Page: 1" } })));
        }
示例#8
0
        public void Can_recognize_company()
        {
            var parsed = new BlockEx(B_Company_AB)
                         .Match(file_content.Skip(1).Take(1).ToArray());

            Assert.True(parsed.Success);
            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new string[0][])));
        }
示例#9
0
        public void Can_extract_information_from_second_block()
        {
            var parsed = new BlockEx(type2)
                         .Match(file_content.Skip(10).Take(6).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(
                            ToTuples(expected_2)));
        }
示例#10
0
 public void Can_recognize_text()
 {
     var parsed = new BlockEx(C_Text_empty)
         .Match(file_content.Skip(2).Take(2).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Text", "Some text" },
                new[] { "Text", "that goes on and explains the report" },
         })));
 }
示例#11
0
        public void Can_recognize_text()
        {
            var parsed = new BlockEx(C_Text_empty)
                         .Match(file_content.Skip(2).Take(2).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Text", "Some text" },
                new[] { "Text", "that goes on and explains the report" },
            })));
        }
示例#12
0
 public void Can_recognize_row_2()
 {
     var parsed = new BlockEx(E_row)
         .Match(file_content.Skip(6).Take(1).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "51" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "B" },
                new[] { "Attribute2", "130" }
     })));
     Assert.True(parsed.Success);
 }
示例#13
0
        public void Can_recognize_row_2()
        {
            var parsed = new BlockEx(E_row)
                         .Match(file_content.Skip(6).Take(1).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "51" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "B" },
                new[] { "Attribute2", "130" }
            })));
            Assert.True(parsed.Success);
        }
示例#14
0
 public void Can_recognize_row()
 {
     var parsed = new BlockEx(E_row)
         .Match(file_content.Skip(5).Take(1).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "44" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "A" },
         })));
     var parsed2 = new BlockEx(E_row)
         .Match(file_content.Skip(6).Take(1).ToArray());
     Assert.That(ToValueTuples(parsed2), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "44" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "B" },
                new[] { "Attribute1", "255" },
                new[] { "Attribute2", "155" }
         })));
 }
示例#15
0
        public void Can_parse_a_simple_specified_format()
        {
            var section = ParseCsv(@";H
            D1;
            D2;
            ;D3");

            var blockEx = new BlockEx(@"
                            _   ""H"" : header
                            @V   _ : row+
                            _   @V : row+");
            var m = blockEx.Match(section);
            Assert.That(ToValueTuples(m), Is.EquivalentTo(ToTuples(
                new[] { new[] { "V", "D1" }, new[] { "V", "D2" }, new[] { "V", "D3" } })));
            Assert.That(ToDictionaries(m), Is.EquivalentTo(new[] {
                ToDictionary(EmptyKvs()),
                ToDictionary(new[] { Kv("V", "D1") }),
                ToDictionary(new[] { Kv("V", "D2") }),
                ToDictionary(new[] { Kv("V", "D3") })
            }));
        }
示例#16
0
        public void Can_recognize_row()
        {
            var parsed = new BlockEx(E_row)
                         .Match(file_content.Skip(5).Take(1).ToArray());

            Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "44" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "A" },
            })));
            var parsed2 = new BlockEx(E_row)
                          .Match(file_content.Skip(6).Take(1).ToArray());

            Assert.That(ToValueTuples(parsed2), Is.EquivalentTo(ToTuples(new[] {
                new[] { "Id", "44" },
                new[] { "Value", "XYZ" },
                new[] { "Type", "B" },
                new[] { "Attribute1", "255" },
                new[] { "Attribute2", "155" }
            })));
        }
 public void Can_extract_entire_thing()
 {
     var header = new BlockEx(string.Join(Environment.NewLine, new[] {
         First_section.A_Report_Title,
         First_section.B_Company_AB,
         First_section.C_Text_empty
     }));
     var split = header.Split(file_content)
         .Where(arr=>arr.Any())
         .ToArray();
     Assert.That(split.Length, Is.EqualTo(3));
     var types = new[] {
         new BlockEx(string.Join(Environment.NewLine, new[] {
             First_section.D_header, First_section.E_row
         })), new BlockEx(string.Join(Environment.NewLine, new[] {
             Second_section.D_header, Second_section.E_row
         }))
     };
     var parsed = split.SelectMany(block =>
         Parse(types, block)
     ).ToArray();
 }
示例#18
0
        public void Can_parse_a_simple_specified_format()
        {
            var section = ParseCsv(@";H
D1;
D2;
;D3");

            var blockEx = new BlockEx(@"
                            _   ""H"" : header 
                            @V   _ : row+
                            _   @V : row+");
            var m       = blockEx.Match(section);

            Assert.That(ToValueTuples(m), Is.EquivalentTo(ToTuples(
                                                              new[] { new[] { "V", "D1" }, new[] { "V", "D2" }, new[] { "V", "D3" } })));
            Assert.That(ToDictionaries(m), Is.EquivalentTo(new[] {
                ToDictionary(EmptyKvs()),
                ToDictionary(new[] { Kv("V", "D1") }),
                ToDictionary(new[] { Kv("V", "D2") }),
                ToDictionary(new[] { Kv("V", "D3") })
            }));
        }
示例#19
0
        public void Can_extract_entire_thing()
        {
            var header = new BlockEx(string.Join(Environment.NewLine, new[] {
                First_section.A_Report_Title,
                First_section.B_Company_AB,
                First_section.C_Text_empty
            }));
            var split = header.Split(file_content)
                        .Where(arr => arr.Any())
                        .ToArray();

            Assert.That(split.Length, Is.EqualTo(3));
            var types = new[] {
                new BlockEx(string.Join(Environment.NewLine, new[] {
                    First_section.D_header, First_section.E_row
                })), new BlockEx(string.Join(Environment.NewLine, new[] {
                    Second_section.D_header, Second_section.E_row
                }))
            };
            var parsed = split.SelectMany(block =>
                                          Parse(types, block)
                                          ).ToArray();
        }
示例#20
0
 public void Can_recognize_company()
 {
     var parsed = new BlockEx(B_Company_AB)
         .Match(file_content.Skip(1).Take(1).ToArray());
     Assert.That(ToValueTuples(parsed), Is.EquivalentTo(ToTuples(new string[0][])));
 }