public void GetCarriageReturnNewLineAsEndOfLine() { Lexer lexer = new Lexer("\r\n"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.EndOfLine, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetNameAndSkipComment() { Lexer lexer = new Lexer("foo # this is a name"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetName() { Lexer lexer = new Lexer("foo"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetLessOrEqualAsOperator() { Lexer lexer = new Lexer("<="); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("<=", token.Value); Assert.AreEqual(TokenType.Operator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetInteger() { Lexer lexer = new Lexer("123"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("123", token.Value); Assert.AreEqual(TokenType.Integer, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetGreaterOperator() { Lexer lexer = new Lexer(">"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(">", token.Value); Assert.AreEqual(TokenType.Operator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetNameSkipCommentAndGetEndOfLineName() { Lexer lexer = new Lexer("foo# this is a name\r\nbar"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.EndOfLine, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("bar", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void RaiseWhenUnclosedString() { Lexer lexer = new Lexer("\"foo"); MyAssert.Throws<LexerException>(() => lexer.NextToken(), "Unclosed String"); }
public void RaiseWhenInvalidCharacter() { Lexer lexer = new Lexer("["); MyAssert.Throws<LexerException>(() => lexer.NextToken(), "Unexpected '['"); }
public void ParseSimpleConditionWithNumbers() { Lexer lexer = new Lexer("30 < 36"); Assert.IsTrue(IsInteger("30", lexer.NextToken())); Assert.IsTrue(IsOperator("<", lexer.NextToken())); Assert.IsTrue(IsInteger("36", lexer.NextToken())); Assert.IsNull(lexer.NextToken()); }
public void ParseSimpleCondition() { Lexer lexer = new Lexer("Temperature > 36"); Assert.IsTrue(IsName("Temperature", lexer.NextToken())); Assert.IsTrue(IsOperator(">", lexer.NextToken())); Assert.IsTrue(IsInteger("36", lexer.NextToken())); Assert.IsNull(lexer.NextToken()); }
public void ParseBooleans() { Lexer lexer = new Lexer("true false"); Assert.IsTrue(IsBoolean("true", lexer.NextToken())); Assert.IsTrue(IsBoolean("false", lexer.NextToken())); Assert.IsNull(lexer.NextToken()); }
public void GetSimpleString() { Lexer lexer = new Lexer("\"foo\""); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.String, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetPeriodAsSeparator() { Lexer lexer = new Lexer("."); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(".", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetNameWithUnderscore() { Lexer lexer = new Lexer("is_not"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("is_not", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public Parser(Lexer lexer) { this.lexer = lexer; }