Пример #1
0
 def test_logical_types(self):
     line = "or and not"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_OR),
         BaseToken(TokenType.T_AND),
         BaseToken(TokenType.T_NOT)
     ]
     self.assertEqual(expected, predicted)
Пример #2
0
 def test_lex_math_operations_types(self):
     line = "+ - * /"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_PLUS),
         BaseToken(TokenType.T_MINUS),
         BaseToken(TokenType.T_MUL),
         BaseToken(TokenType.T_DIV)
     ]
     self.assertEqual(expected, predicted)
Пример #3
0
 def test_lex_data_types(self):
     line = "int double char bool string "
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_INT),
         BaseToken(TokenType.T_DOUBLE),
         BaseToken(TokenType.T_CHAR),
         BaseToken(TokenType.T_BOOL),
         BaseToken(TokenType.T_STRING)
     ]
     self.assertEqual(expected, predicted)
Пример #4
0
 def test_other_types(self):
     line = "if else true false return while = void function"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_IF),
         BaseToken(TokenType.T_ELSE),
         BaseToken(TokenType.T_TRUE),
         BaseToken(TokenType.T_FALSE),
         BaseToken(TokenType.T_RETURN),
         BaseToken(TokenType.T_WHILE),
         BaseToken(TokenType.T_ASSIGN),
         BaseToken(TokenType.T_VOID),
         BaseToken(TokenType.T_FUNCTION)
     ]
     self.assertEqual(expected, predicted)
Пример #5
0
 def find_token(self, line):
     token_args = self._find_token_args(line)
     if not token_args:
         return None
     token_type, value = token_args
     if token_type.has_value_field():
         token = ValueToken(token_type, value)
     else:
         token = BaseToken(token_type)
     return token
Пример #6
0
 def test_lex_punctuation_types(self):
     line = ", . : ; { } ( )"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_COMMA),
         BaseToken(TokenType.T_DOT),
         BaseToken(TokenType.T_COLON),
         BaseToken(TokenType.T_SEMICOLON),
         BaseToken(TokenType.T_LBRACKET),
         BaseToken(TokenType.T_RBRACKET),
         BaseToken(TokenType.T_LPARENT),
         BaseToken(TokenType.T_RPARENT)
     ]
     self.assertEqual(expected, predicted)
Пример #7
0
 def test_math_order_types(self):
     line = "<= < >= > == !="
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         BaseToken(TokenType.T_LESS_OR_EQ),
         BaseToken(TokenType.T_LESS),
         BaseToken(TokenType.T_GREATER_OR_EQ),
         BaseToken(TokenType.T_GREATER),
         BaseToken(TokenType.T_EQ),
         BaseToken(TokenType.T_NOT_EQ)
     ]
     self.assertEqual(expected, predicted)
Пример #8
0
 def test_string(self):
     line = "string"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_STRING)
     self.assertEqual(expected, token)
Пример #9
0
 def test_char(self):
     line = "char"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_CHAR)
     self.assertEqual(expected, token)
Пример #10
0
 def test_double(self):
     line = "double"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_DOUBLE)
     self.assertEqual(expected, token)
Пример #11
0
 def test_and(self):
     line = "and"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_AND)
     self.assertEqual(expected, token)
Пример #12
0
 def test_void(self):
     line = "void"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_VOID)
     self.assertEqual(expected, token)
Пример #13
0
 def test_dot(self):
     line = "."
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_DOT)
     self.assertEqual(expected, token)
Пример #14
0
 def test_while(self):
     line = "while"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_WHILE)
     self.assertEqual(expected, token)
Пример #15
0
 def test_assign(self):
     line = "="
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_ASSIGN)
     self.assertEqual(expected, token)
Пример #16
0
 def test_return(self):
     line = "return"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_RETURN)
     self.assertEqual(expected, token)
Пример #17
0
 def test_false(self):
     line = "false"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_FALSE)
     self.assertEqual(expected, token)
Пример #18
0
 def test_true(self):
     line = "true"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_TRUE)
     self.assertEqual(expected, token)
Пример #19
0
 def test_bool(self):
     line = "bool"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_BOOL)
     self.assertEqual(expected, token)
Пример #20
0
 def test_function(self):
     line = "function"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_FUNCTION)
     self.assertEqual(expected, token)
Пример #21
0
 def test_comma(self):
     line = ","
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_COMMA)
     self.assertEqual(expected, token)
Пример #22
0
 def test_greater(self):
     line = ">"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_GREATER)
     self.assertEqual(expected, token)
Пример #23
0
 def test_greater_or_eq(self):
     line = ">="
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_GREATER_OR_EQ)
     self.assertEqual(expected, token)
Пример #24
0
 def test_less(self):
     line = "<"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_LESS)
     self.assertEqual(expected, token)
Пример #25
0
 def test_not_eq(self):
     line = "!="
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_NOT_EQ)
     self.assertEqual(expected, token)
Пример #26
0
 def test_int(self):
     line = "int"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_INT)
     self.assertEqual(expected, token)
Пример #27
0
 def test_arrow(self):
     line = "->"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_ARROW)
     self.assertEqual(expected, token)
Пример #28
0
 def test_or(self):
     line = "or"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_OR)
     self.assertEqual(expected, token)
Пример #29
0
 def test_specific_to_task_types(self):
     line = "unit phys"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [BaseToken(TokenType.T_UNIT), BaseToken(TokenType.T_PHYS)]
     self.assertEqual(expected, predicted)
Пример #30
0
 def test_unit(self):
     line = "unit"
     token = self.find_token(line)
     expected = BaseToken(TokenType.T_UNIT)
     self.assertEqual(expected, token)