示例#1
0
 public void ItLexesPrograms(string line, IEnumerable<Token> expected)
 {
     var lexer = new Lexer(line.ToStream());
     var tokens = lexer.Lex();
     AssertTokenStreamEquals(expected.ToArray(), tokens.ToArray());
 }
示例#2
0
 public void ItLexesMultpleCloseEndGroups()
 {
     var lexer = new Lexer(
     @"a
     b
     c
     d".ToStream());
     var stream = lexer.Lex().ToArray();
     AssertTokenStreamEquals(stream, new []
         {
             new Token() { Kind = TokenKind.Statement, Value = "a"},
             new Token() { Kind = TokenKind.EOL},
             new Token() { Kind = TokenKind.StartGroup },
             new Token() { Kind = TokenKind.Statement, Value = "b"},
             new Token() { Kind = TokenKind.EOL},
             new Token() { Kind = TokenKind.StartGroup },
             new Token() { Kind = TokenKind.Statement, Value = "c"},
             new Token() { Kind = TokenKind.EOL},
             new Token() { Kind = TokenKind.EndGroup },
             new Token() { Kind = TokenKind.EndGroup },
             new Token() { Kind = TokenKind.Statement, Value = "d"},
             new Token() { Kind = TokenKind.EOL},
             new Token() { Kind = TokenKind.EOF},
         });
 }
示例#3
0
 public void ItFigouresOutGroupStartOrEnd(int spacesBefore,string line, IEnumerable<Token> expected)
 {
     var lexer = new Lexer(line.ToStream());
     lexer.InterpretLine(string.Empty.PadRight(spacesBefore));
     var tokens = lexer.InterpretLine(line).ToArray();
     AssertTokenStreamEquals(expected.ToArray(), tokens);
 }
示例#4
0
 public void ItInterpretsLines(string line, IEnumerable<Token> expected)
 {
     var tokens = new Lexer(line.ToStream()).InterpretLine(line).ToArray();
     AssertTokenStreamEquals(expected.ToArray(), tokens);
 }
示例#5
0
 public void ItDiesOnInconsistentWhitespace(string code)
 {
     var lexer = new Lexer(code.ToStream());
     Assert.Catch<InconsistentWhitespaceException>(() =>lexer.Lex().ToArray());
 }