Beispiel #1
0
        public void ConsumeTokenWhenCalledForEmptyInputReturnsNull()
        {
            var reader = new StringReader(string.Empty);
            var lexer = new CodeLexer(reader, null);

            Assert.That(lexer.NextToken(), Is.Null); 
        }
Beispiel #2
0
        public void PeekNextTokenWhenCalledDoesNotConsumeToken()
        {
            var reader = new StringReader("SET ");
            var lexer = new CodeLexer(reader, new List<TokenBase> { new WhiteSpaceToken(), new InstructionToken() });

            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
        }
Beispiel #3
0
        public void ConsumeTokenWhenCalledWithCommentInputReturnsCommentToken(string input, Type expectedToken)
        {
            var reader = new StringReader(input);
            var lexer = new CodeLexer(reader, this.matchers);

            Assert.That(lexer.NextToken(), Is.InstanceOf(expectedToken));
        }
Beispiel #4
0
        public void CanLexSource1()
        {
            const string Code = @"SET [0x1000], 0x20";
            var reader = new StringReader(Code);
            var lexer = new CodeLexer(reader, this.matchers, new ConsumeTokenStrategy(new IgnoreWhiteSpaceTokenStrategy()));

            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(OpenBracketToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CloseBracketToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
        }
Beispiel #5
0
        public void CanLexSource()
        {
            const string Code = @"DAT 0x10, 0x20, 0x30, 0x40, 0x50
                                 SET I, 0";
            var reader = new StringReader(Code);
            var lexer = new CodeLexer(reader, this.matchers, new ConsumeTokenStrategy(new IgnoreWhiteSpaceTokenStrategy()));

            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(HexToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(RegisterToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(CommaToken)));
            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(DecimalToken)));
        }
Beispiel #6
0
        public void ConsumeTokenWhenCalledIgnoresWhiteSpace()
        {
            var reader = new StringReader(" SET");
            var lexer = new CodeLexer(
                reader,
                new List<TokenBase> { new WhiteSpaceToken(), new InstructionToken() },
                new ConsumeTokenStrategy(new IgnoreWhiteSpaceTokenStrategy()));

            Assert.That(lexer.NextToken(), Is.InstanceOf(typeof(InstructionToken)));
        }
Beispiel #7
0
        public void ConsumeTokenWhenCalledAndNoTokenMatchesInputThrows()
        {
            var reader = new StringReader("A");
            var lexer = new CodeLexer(reader, new List<TokenBase> { new WhiteSpaceToken(), new InstructionToken() });

            Assert.Throws<Exception>(() => lexer.NextToken());
        }