Esempio n. 1
0
        public IEnumerable <Token> Tokenize()
        {
            _resultTokens = new List <Token>();

            while (_reader.Peek() != -1)
            {
                SkipWhitespaces();
                int peekValue = _reader.Peek();
                if (peekValue == -1)
                {
                    break;
                }
                char nextCharacter = (char)peekValue;

                string peekedString;
                switch (nextCharacter)
                {
                case 'c':
                    peekedString = _reader.PeekWithBufferingUntil(TokenSemantics.ClassnameOrVariableSearchDelimiters);
                    _resultTokens.Add(ParseIfClassOpeningToken(peekedString));
                    break;

                case '}':
                    _resultTokens.Add(ParseIfClosingToken());
                    break;

                case 't':
                    peekedString = _reader.PeekWithBufferingUntil(TokenSemantics.ClassnameOrVariableSearchDelimiters);
                    _resultTokens.Add(ParseIfTypeOpeningToken(peekedString));
                    break;

                case '"':
                    _resultTokens.Add(ParseIfStandaloneStringToken());
                    break;

                default:
                    peekedString = _reader.PeekWithBufferingUntil(TokenSemantics.ClassnameOrVariableSearchDelimiters);
                    _resultTokens.Add(ParseIfVariableToken(peekedString));
                    break;
                }
                _reader.Read();
            }
            return(_resultTokens);
        }
        public string PeekWithBufferingUntil_PeeksAllCharactersUntilAnyGivenCharWithoutConsuming(string text, char[] breakingCharactersArray)
        {
            //Arrange
            _stringReader = new StringReader(text);
            _peekableStringReaderAdapter = new PeekableStringReaderAdapter(_stringReader);

            //Act
            var peekedCharacters = _peekableStringReaderAdapter.PeekWithBufferingUntil(breakingCharactersArray);

            //Assert
            Assert.AreEqual(peekedCharacters[0], (char)_peekableStringReaderAdapter.Peek());
            return(peekedCharacters);
        }
        public void ConsumeBuffer_ClearsBuffer()
        {
            // Arrange
            string testText = "#consumed part/not consumed part";

            _stringReader = new StringReader(testText);
            _peekableStringReaderAdapter = new PeekableStringReaderAdapter(_stringReader);

            var peekedPart = _peekableStringReaderAdapter.PeekWithBufferingUntil('/');

            Assert.AreEqual(peekedPart[0], _peekableStringReaderAdapter.Peek());

            //Act
            _peekableStringReaderAdapter.ConsumeBuffer();

            //Assert
            Assert.AreNotEqual(peekedPart[0], _peekableStringReaderAdapter.Peek());
        }