public void can_instantiate_a_valid_object()
            {
                const string textToRead = @"abc 123 if  while for titan + + *";

                using (TextReader textReader = new StringReader(textToRead))
                {
                    var parseReader = new ParseReader(textReader);
                    var tokenizer = new Tokenizer(parseReader);

                    Assert.IsNotNull(tokenizer);
                }
            }
            public void returns_a_symbol_token_as_first_token()
            {
                const int tokenIndex = 1;
                int currentIndex = 1;
                using (var textReader = new StringReader(textToRead))
                using (var parseReader = new ParseReader(textReader))
                {
                    _tokenizer = new Tokenizer(parseReader);

                    while (true)
                    {
                        var token = _tokenizer.NextToken();

                        if (tokenIndex == currentIndex)
                        {
                            Assert.AreEqual(token.GetText(), "abc");
                            Assert.IsInstanceOfType(token.GetType(), typeof (Symbol));
                            break;
                        }
                        currentIndex++;
                    }
                }
            }
            public void returns_a_keyword_as_sixth_token()
            {
                // Assemble
                using (var textReader = new StringReader(textToRead))
                using (var parseReader = new ParseReader(textReader))
                {
                    _tokenizer = new Tokenizer(parseReader);

                    const int tokenIndex = 6;
                    int currentIndex = 1;

                    while (true)
                    {
                        // Act
                        var token = _tokenizer.NextToken();

                        if (tokenIndex == currentIndex)
                        {
                            //Assert
                            Assert.AreEqual(token.GetText(), "if");
                            Assert.IsInstanceOfType(token.GetType(), typeof (If));
                            break;
                        }
                        currentIndex++;
                    }
                }
            }
 public void Init()
 {
     textReader = new StringReader(stringToRead);
     reader = new ParseReader(textReader);
 }
            public void returns_a_string_literal_as_fourth_token()
            {
                // Assemble
                using (var textReader = new StringReader(textToRead))
                using (var parseReader = new ParseReader(textReader))
                {
                    _tokenizer = new Tokenizer(parseReader);

                    const int tokenIndex = 4;
                    int currentIndex = 1;

                    while (true)
                    {
                        // Act
                        var token = _tokenizer.NextToken();

                        if (tokenIndex == currentIndex)
                        {
                            //Assert
                            Assert.AreEqual(token.GetText(), "My input string");
                            Assert.IsInstanceOfType(token.GetType(), typeof (String));
                            break;
                        }
                        currentIndex++;
                    }
                }
            }
Ejemplo n.º 6
0
 public Tokenizer(ParseReader input)
     : this()
 {
     _input = input;
 }