def test_literal(self): ''' Simple literal should compile directly. ''' token = Token(Literal('abc')) token.compile() assert token.regexp == 'abc', repr(token.regexp)
def test_float(self): ''' A float is more complex, but still compiles. ''' token = Token(Float()) token.compile() assert token.regexp == \ '(?:[\\+\\-])?(?:(?:[0-9](?:[0-9])*)?\\.[0-9](?:[0-9])*|[0-9](?:[0-9])*(?:\\.)?)(?:[Ee](?:[\\+\\-])?[0-9](?:[0-9])*)?', \ repr(token.regexp)
def test_impossible(self): ''' Cannot compile arbitrary functions. ''' try: token = Token(Float() > (lambda x: x)) token.compile() assert False, 'Expected error' except LexerError: pass
def test_float(self): ''' A float is more complex, but still compiles. ''' token = Token(Float()) token.compile() assert token.regexp == \ '([\\+\\-]|)(([0-9]([0-9])*|)\\.[0-9]([0-9])*|' \ '[0-9]([0-9])*(\\.|))([Ee]([\\+\\-]|)[0-9]([0-9])*|)', \ repr(token.regexp)