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)
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)
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
def test_int_value(self): line = "152" token = self.find_token(line) expected = ValueToken(TokenType.VT_INT, "152") self.assertEqual(expected, token)
def test_char_value(self): line = "'c'" token = self.find_token(line) expected = ValueToken(TokenType.VT_CHAR, "'c'") self.assertEqual(expected, token)
def test_string_value(self): line = '"test string"' token = self.find_token(line) expected = ValueToken(TokenType.VT_STRING, '"test string"') self.assertEqual(expected, token)
def test_double_value(self): line = "2.5" token = self.find_token(line) expected = ValueToken(TokenType.VT_DOUBLE, "2.5") self.assertEqual(expected, token)
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)