-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsetest.py
36 lines (27 loc) · 1.43 KB
/
parsetest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import unittest
from parse import DataParser
from rule import ParseRule
from languagetype import Language, LanguageType
class Test_TestParse(unittest.TestCase):
def test_parse_type(self):
parser = DataParser()
self.assertEqual(parser.parse_type('Hippos eat grass'), LanguageType.string)
self.assertEqual(parser.parse_type('0123'), LanguageType.string)
self.assertEqual(parser.parse_type('0.43'), LanguageType.float)
self.assertEqual(parser.parse_type('.32'), LanguageType.float)
self.assertEqual(parser.parse_type('100'), LanguageType.integer)
self.assertEqual(parser.parse_type('$650 Switcher registration'), LanguageType.string)
def test_parse_type_translate(self):
parser = DataParser()
self.assertEqual(parser.translate_type(LanguageType.string, Language.Java), 'String')
self.assertEqual(parser.translate_type(LanguageType.string, Language.Typescript), 'string')
self.assertEqual(parser.translate_type(LanguageType.integer, Language.Typescript), 'number')
def test_parse_type_order(self):
""" Test parsing a type where I order a BigInt mapping in front of int """
parser = DataParser()
rules = parser.rules
rules.insert(0, ParseRule('matches', r'\d*', 'BigInt'))
parser.rules = rules
self.assertEqual(parser.parse_type('100'), 'BigInt')
if __name__ == '__main__':
unittest.main()