File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,13 +111,16 @@ def convertTuple(t):
111111recordMember = delimitedList (Group (ident + Suppress ('=' ) + omcValue ))
112112omcRecord << Group (Suppress ('record' ) + Suppress (fqident ) + Dict (recordMember ) + Suppress ('end' ) + Suppress (fqident ) + Suppress (';' )).setParseAction (convertDict )
113113
114- omcGrammar = omcValue + StringEnd ()
114+ omcGrammar = Optional ( omcValue ) + StringEnd ()
115115
116116omcNumber .setParseAction (convertNumbers )
117117
118118
119119def parseString (string ):
120- return omcGrammar .parseString (string )[0 ]
120+ res = omcGrammar .parseString (string )
121+ if len (res ) == 0 :
122+ return
123+ return res [0 ]
121124
122125
123126if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ def testFloat(self):
3434 # def testDict(self):
3535 # self.assertEqual(type(typeCheck('{"a": "b"}')), dict)
3636
37+ def testIdent (self ):
38+ self .assertEqual (typeCheck ('blabla2' ), "blabla2" )
39+ pass
40+
3741 def testStr (self ):
3842 pass
3943
Original file line number Diff line number Diff line change 1+ from __future__ import absolute_import
2+ from __future__ import division
3+ from __future__ import print_function
4+ from builtins import int
5+
6+ from OMPython import OMTypedParser
7+
8+ import unittest
9+
10+ typeCheck = OMTypedParser .parseString
11+
12+
13+ class TypeCheckTester (unittest .TestCase ):
14+ def testNewlineBehaviour (self ):
15+ pass
16+
17+ def testBoolean (self ):
18+ self .assertEqual (typeCheck ('true' ), True )
19+ self .assertEqual (typeCheck ('false' ), False )
20+
21+ def testInt (self ):
22+ self .assertEqual (typeCheck ('2' ), 2 )
23+ self .assertEqual (type (typeCheck ('1' )), int )
24+ self .assertEqual (type (typeCheck ('123123123123123123232323' )), int )
25+ self .assertEqual (type (typeCheck ('9223372036854775808' )), int )
26+
27+ def testFloat (self ):
28+ self .assertEqual (type (typeCheck ('1.2e3' )), float )
29+
30+ def testIdent (self ):
31+ self .assertEqual (typeCheck ('blabla2' ), "blabla2" )
32+ pass
33+
34+ def testEmpty (self ):
35+ self .assertEqual (typeCheck ('' ), None )
36+ pass
37+
38+ def testStr (self ):
39+ pass
40+
41+ def testUnStringable (self ):
42+ pass
43+
44+
45+ if __name__ == '__main__' :
46+ unittest .main ()
You can’t perform that action at this time.
0 commit comments