Exemple #1
0
    private static void RunTest()
    {
        var    parser = new ManualParser();
        string csv    = Properties.Resources.Csv;
        var    result = new StringBuilder();
        var    s      = new Stopwatch();

        for (int test = 0; test < 3; test++)
        {
            int lineCount = 0;
            s.Start();
            for (int i = 0; i < 1000000 / 50; i++)
            {
                foreach (var line in csv.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                {
                    string cur = line + s.ElapsedTicks.ToString();
                    result.AppendLine(parser.Parse(cur).ToString());
                    lineCount++;
                }
            }
            s.Stop();
            Console.WriteLine("Completed {0} lines in {1}ms", lineCount, s.ElapsedMilliseconds);
            s.Reset();
            result = new StringBuilder();
        }
    }
        public void Test_ManualParser_OnSomeInputString()
        {
            var parser = new ManualParser();

            parser.ParseBlock($"<a>Hello world</a>");
            var texts = parser.ResultTexts.ToList();

            Assert.AreEqual(1, texts.Count);
            Assert.AreEqual("Hello world", texts[0]);
        }
    public void Parse_GivenStringWithNoQuotesAndNoCommas_ShouldReturnThatString()
    {
        // Arrange
        var parser = new ManualParser();

        // Act
        string[] result = parser.Parse("This is my data").ToArray();
        // Assert
        Assert.AreEqual(1, result.Length, "Should only be one column returned");
        Assert.AreEqual("This is my data", result[0], "Incorrect value is returned");
    }
    public void Parse_GivenStringWithQuotesAndNoCommas_ShouldReturnColumnWithoutQuotes()
    {
        // Arrange
        var parser = new ManualParser();

        // Act
        string[] result = parser.Parse("\"This is my data\"").ToArray();
        // Assert
        Assert.AreEqual(1, result.Length, "Should be 1 column returned");
        Assert.AreEqual("This is my data", result[0], "Value is incorrect");
    }
Exemple #5
0
        private async Task ParseByBlocks(StreamReader streamReader, ManualParser parser)
        {
            var buffer = new char[Configuration.BufferSize];

            while (!streamReader.EndOfStream)
            {
                var count = await streamReader.ReadBlockAsync(buffer, 0, Configuration.BufferSize);

                var textBlock = count == Configuration.BufferSize
                    ? new string(buffer)
                    : new string(buffer[..count]);
    public void Parse_GivenStringWithQuotesContainingCommasAndCommas_ShouldReturnColumnsWithoutQuotes()
    {
        // Arrange
        var parser = new ManualParser();

        // Act
        string[] result = parser.Parse("\"This, is\", my data").ToArray();
        // Assert
        Assert.AreEqual(2, result.Length, "Should be 2 columns returned");
        Assert.AreEqual("This, is", result[0], "First value is incorrect");
        Assert.AreEqual("my data", result[1], "Second value is incorrect");
    }
    public void Parse_GivenStringWithNoQuotesAndOneComma_ShouldReturnTwoColumns()
    {
        // Arrange
        var parser = new ManualParser();

        // Act
        string[] result = parser.Parse("This is, my data").ToArray();
        // Assert
        Assert.AreEqual(2, result.Length, "Should be 2 columns returned");
        Assert.AreEqual("This is", result[0], "First value is incorrect");
        Assert.AreEqual("my data", result[1], "Second value is incorrect");
    }
Exemple #8
0
        /// <summary>
        /// Основной метод запуска парсинга
        /// </summary>
        /// <param name="streamReader">Входной поток</param>
        public override async Task Parse(StreamReader streamReader)
        {
            var parser = new ManualParser(Configuration.ExcludeTags);

            await ParseByBlocks(streamReader, parser);

            var texts = parser.ResultTexts;

            var wordsDict = ExtractUniqueWords(texts);

            PrintReport(wordsDict);
        }
        public void Test_ManualParser_OnFullReadFile_And_Count_ResultTexts()
        {
            var fileName = Path.Combine(TestContext.CurrentContext.GetTestProjectPath(),
                                        @"SampleFiles\Создаем программное обеспечение для бизнеса - SimbirSoft.html");

            var fileContent = File.ReadAllText(fileName);

            var configuration = ParseConfiguration.Default();
            var parser        = new ManualParser(configuration.ExcludeTags);

            parser.ParseBlock(fileContent);

            Assert.AreEqual(250, parser.ResultTexts.Count());
        }
    static void Main(string[] args)
    {
        var    parser    = new ManualParser();
        string csv       = Properties.Resources.Csv;
        var    result    = new StringBuilder();
        var    s         = new Stopwatch();
        int    lineCount = 0;

        s.Start();
        for (int i = 0; i < 3000; i++)
        {
            foreach (var line in csv.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
            {
                result.AppendLine(parser.Parse(line).ToString());
                lineCount++;
            }
        }
        s.Stop();
        Console.WriteLine("Completed {0} lines in {1}ms", lineCount, s.ElapsedMilliseconds);
    }
Exemple #11
0
 internal static int ERParser(ManualParser.Parser.Code e)
 {
     return ((int) e) + 2100;
 }
Exemple #12
0
 internal static int ERLexer(ManualParser.Lexer.ErrorCode e)
 {
     return ((int) e) + 2000;
 }
Exemple #13
0
 internal ErrorException(ManualParser.Parser.Code e, FileRange location, string stMessage) 
     : this(ERParser(e), location, stMessage) { }
Exemple #14
0
        public void Test_ManualParser_OnWrongInputString()
        {
            var parser = new ManualParser();

            Assert.Throws <ParseException>(() => { parser.ParseBlock($"<a>Hello world</span>"); });
        }