Пример #1
0
 def test_id(self):
     line = "var_name x y z"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         ValueToken(TokenType.VT_ID, "var_name"),
         ValueToken(TokenType.VT_ID, "x"),
         ValueToken(TokenType.VT_ID, "y"),
         ValueToken(TokenType.VT_ID, "z")
     ]
     self.assertEqual(expected, predicted)
Пример #2
0
 def test_const_values(self):
     line = "'c' \"string\" 5 2.5 |n*n/sm*q|"
     predicted = self.lexer._get_tokens_from_line(line)
     expected = [
         ValueToken(TokenType.VT_CHAR, "'c'"),
         ValueToken(TokenType.VT_STRING, '"string"'),
         ValueToken(TokenType.VT_INT, "5"),
         ValueToken(TokenType.VT_DOUBLE, "2.5"),
         ValueToken(TokenType.VT_UNIT, "|n*n/sm*q|")
     ]
     self.assertEqual(expected, predicted)
Пример #3
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
Пример #4
0
 def test_int_value(self):
     line = "152"
     token = self.find_token(line)
     expected = ValueToken(TokenType.VT_INT, "152")
     self.assertEqual(expected, token)
Пример #5
0
 def test_char_value(self):
     line = "'c'"
     token = self.find_token(line)
     expected = ValueToken(TokenType.VT_CHAR, "'c'")
     self.assertEqual(expected, token)
Пример #6
0
 def test_string_value(self):
     line = '"test string"'
     token = self.find_token(line)
     expected = ValueToken(TokenType.VT_STRING, '"test string"')
     self.assertEqual(expected, token)
Пример #7
0
 def test_double_value(self):
     line = "2.5"
     token = self.find_token(line)
     expected = ValueToken(TokenType.VT_DOUBLE, "2.5")
     self.assertEqual(expected, token)
Пример #8
0
 def test_unit_value(self):
     line = "|m/s*s|"
     token = self.find_token(line)
     expected = ValueToken(TokenType.VT_UNIT, "|m/s*s|")
     self.assertEqual(expected, token)