public void Should_not_move_forward_when_using_peek() { // Given when var scanner = new Lexer(Tokenizer.OfString("1 + 3")); // Then ((LiteralToken)scanner.PeekToken()).Value.Should().Be(1D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(1D); // Then scanner.PeekToken().Type.Should().Be(TokenType.Plus); scanner.NextToken().Type.Should().Be(TokenType.Plus); // Then ((LiteralToken)scanner.PeekToken()).Value.Should().Be(3D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(3D); // Then scanner.PeekToken().Should().BeNull(); scanner.NextToken().Should().BeNull(); }
public void Should_lex_expression_with_modulo() { // Given when var scanner = new Lexer(Tokenizer.OfString("10 % 2")); ((LiteralToken)scanner.PeekToken()).Value.Should().Be(10D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(10D); // Then scanner.PeekToken().Type.Should().Be(TokenType.Modulo); scanner.NextToken().Type.Should().Be(TokenType.Modulo); }
public void Should_lex_expression_formed_by_a_single_positive_number_with_plus_sign_explicit() { // Given when var scanner = new Lexer(Tokenizer.OfString("+123")); // Then scanner.PeekToken().Type.Should().Be(TokenType.Plus); scanner.NextToken().Type.Should().Be(TokenType.Plus); ((LiteralToken)scanner.PeekToken()).Value.Should().Be(123D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(123D); }
public void Should_lex_expression_formed_by_a_single_negative__decimal_number_with_zero_omitted() { // Given when var scanner = new Lexer(Tokenizer.OfString("-.123")); // Than scanner.PeekToken().Type.Should().Be(TokenType.Minus); scanner.NextToken().Type.Should().Be(TokenType.Minus); ((LiteralToken)scanner.PeekToken()).Value.Should().Be(.123D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(.123D); }
public void Should_lex_expression_formed_by_a_single_number() { // Given when var scanner = new Lexer(Tokenizer.OfString("123")); // Then ((LiteralToken)scanner.PeekToken()).Value.Should().Be(123D); ((LiteralToken)scanner.NextToken()).Value.Should().Be(123D); }