public void TakeReturnsTheFirstToken() { //Act var result = _keeper.Take(); //Assert result.TokenType.Should().Be(TokenType.OpenParens); }
private static bool TryTakeCloseParens(TokenKeeper pos) { if (pos.Next.TokenType == TokenType.CloseParens) { pos.Take(); return(true); } return(false); }
private static bool TryTakeToken(TokenType tokenType, TokenKeeper pos) { if (pos.Next.TokenType == tokenType) { pos.Take(); return(true); } return(false); }
private static bool TryTakeOperator(TokenKeeper pos, out OperatorToken op) { if (pos.Next.TokenType == TokenType.Operator) { op = pos.Take() as OperatorToken; return(true); } op = null; return(false); }
private static bool TryTakeNumericLiteral(TokenKeeper pos, out ExpressionNode node) { if (pos.Next.TokenType == TokenType.NumericLiteral) { node = new NumericLiteralNode(pos.Take()); return(true); } node = null; return(false); }
public void SwapExchangesPositionWithOtherTokenKeeper() { //Arrange var other = new TokenKeeper(_keeper); other.Take(); //Act _keeper.Swap(other); //Assert other.IsNext(TokenType.OpenParens).Should().BeTrue(); }
public void SwapTakesPositionFromOtherTokenKeeper() { //Arrange var other = new TokenKeeper(_keeper); other.Take(); //Act _keeper.Swap(other); //Assert _keeper.IsNext(TokenType.NumericLiteral).Should().BeTrue(); }
public void DiscardWhileShouldConsumeAllMatchingTokens() { //Arrange var original = new TokenKeeper(_keeper); //Act _keeper.DiscardWhile(TokenType.OpenParens, TokenType.NumericLiteral, TokenType.Operator); //Assert while (original.Next.TokenType != TokenType.CloseParens) { original.Take(); } var remaining = _keeper.RemainingData(); remaining.Should().Be(original.RemainingData()); }