public void ItLexesPrograms(string line, IEnumerable<Token> expected) { var lexer = new Lexer(line.ToStream()); var tokens = lexer.Lex(); AssertTokenStreamEquals(expected.ToArray(), tokens.ToArray()); }
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}, }); }
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); }
public void ItInterpretsLines(string line, IEnumerable<Token> expected) { var tokens = new Lexer(line.ToStream()).InterpretLine(line).ToArray(); AssertTokenStreamEquals(expected.ToArray(), tokens); }
public void ItDiesOnInconsistentWhitespace(string code) { var lexer = new Lexer(code.ToStream()); Assert.Catch<InconsistentWhitespaceException>(() =>lexer.Lex().ToArray()); }