Beispiel #1
0
    def test_should_recognize_the_left_arrow_operator(self):
        lexer = Lexer('<-')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.LEFT_ARROW)
        self.assertEqual(token.value, '<-')
Beispiel #2
0
    def test_should_recognize_a_string_containing_an_espaced_backslash(self):
        lexer = Lexer('"a string with a \\\\ backslash"')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.STRING)
        self.assertEqual(token.value, '"a string with a \\\\ backslash"')
Beispiel #3
0
    def test_should_recognize_a_string_containing_escape_sequences(self):
        lexer = Lexer('"a string containing \\t\\b\\r\\f\\v\\0 escape sequences"')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.STRING)
        self.assertEqual(token.value, '"a string containing \\t\\b\\r\\f\\v\\0 escape sequences"')
Beispiel #4
0
    def test_should_recognize_decimal_in_scientific_notation_with_negative_exponent_part(self):
        lexer = Lexer('42e-65')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DECIMAL)
        self.assertEqual(token.value, '42e-65')
Beispiel #5
0
    def test_should_recognize_a_left_parenthesis(self):
        lexer = Lexer('(')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.LEFT_PAREN)
        self.assertEqual(token.value, '(')
Beispiel #6
0
    def test_should_recognize_a_comma(self):
        lexer = Lexer(',')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.COMMA)
        self.assertEqual(token.value, ',')
Beispiel #7
0
    def test_should_recognize_a_right_bracket(self):
        lexer = Lexer(']')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.RIGHT_BRACKET)
        self.assertEqual(token.value, ']')
Beispiel #8
0
    def test_should_recognize_the_plus_operator(self):
        lexer = Lexer('+')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.PLUS)
        self.assertEqual(token.value, '+')
Beispiel #9
0
    def test_should_recognize_the_times_operator(self):
        lexer = Lexer('*')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.TIMES)
        self.assertEqual(token.value, '*')
Beispiel #10
0
    def test_should_recognize_the_div_operator(self):
        lexer = Lexer('/')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DIV)
        self.assertEqual(token.value, '/')
Beispiel #11
0
    def test_should_recognize_the_modulo_operator(self):
        lexer = Lexer('%')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.MOD)
        self.assertEqual(token.value, '%')
Beispiel #12
0
    def test_should_recognize_the_right_arrow_operator(self):
        lexer = Lexer('->')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.RIGHT_ARROW)
        self.assertEqual(token.value, '->')
Beispiel #13
0
    def test_should_recognize_the_minus_equal_operator(self):
        lexer = Lexer('-=')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.MINUS_EQUAL)
        self.assertEqual(token.value, '-=')
Beispiel #14
0
    def test_should_recognize_simple_decimal_literal(self):
        lexer = Lexer('3.14')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DECIMAL)
        self.assertEqual(token.value, '3.14')
Beispiel #15
0
    def test_should_recognize_a_colon(self):
        lexer = Lexer(':')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.COLON)
        self.assertEqual(token.value, ':')
Beispiel #16
0
    def test_should_recognize_decimal_starting_with_dot(self):
        lexer = Lexer('.25')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DECIMAL)
        self.assertEqual(token.value, '.25')
Beispiel #17
0
    def test_should_recognize_decimal_in_scientific_notation(self):
        lexer = Lexer('2e65')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DECIMAL)
        self.assertEqual(token.value, '2e65')
Beispiel #18
0
    def test_should_recognize_the_double_equal_operator(self):
        lexer = Lexer('==')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.DOUBLE_EQUAL)
        self.assertEqual(token.value, '==')
Beispiel #19
0
    def test_should_recognize_a_left_bracket(self):
        lexer = Lexer('[')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.LEFT_BRACKET)
        self.assertEqual(token.value, '[')
Beispiel #20
0
    def test_should_recognize_the_greater_or_equal_operator(self):
        lexer = Lexer('>=')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.GREATER_OR_EQUAL)
        self.assertEqual(token.value, '>=')
Beispiel #21
0
    def test_should_recognize_newline_character_as_single_token(self):
        lexer = Lexer('\n')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.NEWLINE)
        self.assertEqual(token.value, '\n')
Beispiel #22
0
    def test_should_recognize_the_less_or_equal_operator(self):
        lexer = Lexer('<=')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.LESS_OR_EQUAL)
        self.assertEqual(token.value, '<=')
Beispiel #23
0
    def test_should_recognize_simple_string_literal(self):
        lexer = Lexer('"Hello, World!"')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.STRING)
        self.assertEqual(token.value, '"Hello, World!"')
Beispiel #24
0
    def test_should_recognize_the_and_operator(self):
        lexer = Lexer('&&')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.AND)
        self.assertEqual(token.value, '&&')
Beispiel #25
0
    def test_should_recognize_string_containing_a_newline_character(self):
        lexer = Lexer('"a string containing a \\n newline character."')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.STRING)
        self.assertEqual(token.value, '"a string containing a \\n newline character."')
Beispiel #26
0
    def test_should_recognize_the_not_operator(self):
        lexer = Lexer('!')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.NOT)
        self.assertEqual(token.value, '!')
Beispiel #27
0
    def test_should_recognize_a_string_containing_escaped_double_quotes(self):
        lexer = Lexer('"a string containing an \\" escaped double quote"')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.STRING)
        self.assertEqual(token.value, '"a string containing an \\" escaped double quote"')
Beispiel #28
0
    def test_should_recognize_the_or_operator(self):
        lexer = Lexer('||')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.OR)
        self.assertEqual(token.value, '||')
Beispiel #29
0
    def test_should_recognize_an_identifier_of_a_single_letter(self):
        lexer = Lexer('i')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.IDENTIFIER)
        self.assertEqual(token.value, 'i')
Beispiel #30
0
    def test_should_recognize_an_identifier_starting_with_a_reserved_keyword(self):
        lexer = Lexer('toString')
        token = lexer.next_token()

        self.assertEqual(token.type, TokenType.IDENTIFIER)
        self.assertEqual(token.value, 'toString')