public void TestPositionAfterMultiParsing()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("\'t\'\'t\'\'t\'\'t\'\'t\'");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();

            // Act

            var startStreamPos = stream.Position;

            var result = new List <IRule> {
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context)
            };

            var endStreamPosition = stream.Position;


            // Assert

            Assert.AreEqual(startStreamPos + (result.Count * 3), endStreamPosition);
        }
        public void TestParseRuleSuccessManySymbols()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("\'t\'\'t\'\'t\'\'t\'\'t\'");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();

            // Act
            var result = new List <IRule> {
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context),
                parser.Parse(context)
            };


            // Assert

            result.ForEach(Assert.IsNotNull);
        }
Пример #3
0
        public void Should_parse_text_from_the_string()
        {
            var input = new StringText("Hello, World.");

            var parser = new SymbolParser(char.IsLetter, char.IsLetterOrDigit);

            var result = parser.Parse(input, new TextSpan(0, input.Length));

            Assert.IsTrue(result.HasValue);

            var text = input.GetSubText(result.Value);

            Assert.AreEqual("Hello", text.ToString());
        }
        public void TestParseRuleFailWithOneSymbol()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("a");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();

            // Act

            var result = parser.Parse(context);

            // Assert

            Assert.IsNull(result);
        }
        public void TestParseRuleSuccessWithManySymbols()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("\'t\'sdjhfgjhsdgf");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();

            // Act

            var result = parser.Parse(context);

            // Assert

            Assert.IsNotNull(result);
        }
        public void TestParseRuleFailWithSymbolParserTooMuchSymbolsException()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("\'asfasdasdasd\'werwer");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();

            // Act

            var action = new Action(() => { parser.Parse(context); });


            // Assert
            Assert.ThrowsException <SymbolParserTooMuchSymbolsException>(action);
        }
Пример #7
0
        public async Task CanParseRawSymbolsString()
        {
            var rawString = await DataHelper.GetRawSymbolsString().ConfigureAwait(false);

            var symbols = SymbolParser.Parse(rawString);

            Assert.True(symbols.Count > 0);

            foreach (var symbol in symbols)
            {
#if DEBUG
                Console.WriteLine(symbol.ToJson());
#endif
                Assert.NotNull(symbol.Code); // may be empty
                Assert.False(symbol.Id == 0);
                Assert.False(string.IsNullOrEmpty(symbol.Name));
                Assert.False(symbol.MarketId == 0);
            }
        }
        public void TestPositionAfterFailedParsing()
        {
            // Arrange

            var stream  = new MemoryStream().FromString("a");
            var context = new DefaultParserContext(stream: stream);
            var parser  = new SymbolParser();


            // Act

            var startPos = stream.Position;

            parser.Parse(context);
            var endPos = stream.Position;

            // Assert

            Assert.AreEqual(endPos, startPos);
        }
Пример #9
0
        private string WorkOnTextBox(IAwareXmlTextReader xmlReader)
        {
            string value = string.Empty;

            while (xmlReader.Read())
            {
                string text = null;
                if (xmlReader.NodeType == XmlNodeType.Text)
                {
                    text = xmlReader.Value.HtmlTrim();
                }
                else if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "img")
                {
                    text = SymbolParser.Parse(xmlReader);
                }

                if (!string.IsNullOrWhiteSpace(text))
                {
                    value += " " + text;
                }
            }

            return(value.HtmlTrim());
        }
Пример #10
0
        public async Task <IList <Symbol> > LoadSymbols()
        {
            var data = await this.requestor.GetString(this.symbolsFeedUrl).ConfigureAwait(false);

            return(SymbolParser.Parse(data));
        }
Пример #11
0
        public static async Task <IList <Symbol> > GetSymbolsFromRawDataFile()
        {
            var source = await GetRawSymbolsString().ConfigureAwait(false);

            return(SymbolParser.Parse(source));
        }
Пример #12
0
        public void ParseEmptyStringReturnsEmptyList()
        {
            var res = SymbolParser.Parse(string.Empty);

            Assert.AreEqual(0, res.Count);
        }
Пример #13
0
        public void ParseNullStringReturnsEmptyList()
        {
            var res = SymbolParser.Parse(null);

            Assert.AreEqual(0, res.Count);
        }