Exemplo n.º 1
0
    def findMatchPattern(self, source, pattern, start, end):
        # Test data
        stream = Stream(source, 'Unit Test Stream')
        stream.element_buffer = list(source)
        if pattern == Element.EOS:
            stream.current_position = len(stream.element_buffer)
        transition = LexerStateTransition(pattern, start, end, True, None,
                                          'Unit Test State Transition')

        # Show test data
        LexerStateTransitionTest.logger.debug('Created stream:\n%s' %
                                              (stream.to_pretty_json()))
        LexerStateTransitionTest.logger.debug('Created state transition:\n%s' %
                                              (transition.to_pretty_json()))

        # Run test
        data = transition.findMatch(stream)
        new_buffer = stream.element_buffer

        # Show test output
        LexerStateTransitionTest.logger.debug('Token data found: "%s"' %
                                              (data))
        LexerStateTransitionTest.logger.debug('New buffer: %s' %
                                              (str(new_buffer)))
        LexerStateTransitionTest.logger.debug('Final stream state:\n%s' %
                                              (stream.to_pretty_json()))

        return (data, new_buffer)
Exemplo n.º 2
0
 def testGetTokenData(self):
     LexerStateTransitionTest.logger.debug('Testing the matching of a sequence.')
     
     # Test data
     location = (3, 4)
     start_offet = 0
     end_offset = 4
     source = 'Jul 11 09:51:54'
     stream = Stream(source, 'Unit Test Stream')
     stream.element_buffer = list(source)
     transition = LexerStateTransition('', start_offet, end_offset, True, None, 'Unit Test State Transition')
     
     # Show test data
     LexerStateTransitionTest.logger.debug('Created stream:\n%s' % (stream.to_pretty_json()))
     LexerStateTransitionTest.logger.debug('Created state transition:\n%s' % (transition.to_pretty_json()))
     
     # Run test
     data = transition.getTokenData(stream, location)
     
     # Show test output
     LexerStateTransitionTest.logger.debug('Token data found: "%s"' % (data))
     LexerStateTransitionTest.logger.debug('Final stream state:\n%s' % (stream.to_pretty_json()))
     
     # Verify results
     assert data == source[:location[0]], 'The data from the accepted buffer is incorrect.'
     
     LexerStateTransitionTest.logger.debug('Test succeeded!')
Exemplo n.º 3
0
    def testGetTokenData(self):
        LexerStateTransitionTest.logger.debug(
            'Testing the matching of a sequence.')

        # Test data
        location = (3, 4)
        start_offet = 0
        end_offset = 4
        source = 'Jul 11 09:51:54'
        stream = Stream(source, 'Unit Test Stream')
        stream.element_buffer = list(source)
        transition = LexerStateTransition('', start_offet, end_offset, True,
                                          None, 'Unit Test State Transition')

        # Show test data
        LexerStateTransitionTest.logger.debug('Created stream:\n%s' %
                                              (stream.to_pretty_json()))
        LexerStateTransitionTest.logger.debug('Created state transition:\n%s' %
                                              (transition.to_pretty_json()))

        # Run test
        data = transition.getTokenData(stream, location)

        # Show test output
        LexerStateTransitionTest.logger.debug('Token data found: "%s"' %
                                              (data))
        LexerStateTransitionTest.logger.debug('Final stream state:\n%s' %
                                              (stream.to_pretty_json()))

        # Verify results
        assert data == source[:location[
            0]], 'The data from the accepted buffer is incorrect.'

        LexerStateTransitionTest.logger.debug('Test succeeded!')
Exemplo n.º 4
0
 def findMatchPattern(self, source, pattern, start, end):
     # Test data
     stream = Stream(source, 'Unit Test Stream')
     stream.element_buffer = list(source)
     if pattern == Element.EOS:
         stream.current_position = len(stream.element_buffer)
     transition = LexerStateTransition(pattern, start, end, True, None, 'Unit Test State Transition')
     
     # Show test data
     LexerStateTransitionTest.logger.debug('Created stream:\n%s' % (stream.to_pretty_json()))
     LexerStateTransitionTest.logger.debug('Created state transition:\n%s' % (transition.to_pretty_json()))
     
     # Run test
     data = transition.findMatch(stream)
     new_buffer = stream.element_buffer
     
     # Show test output
     LexerStateTransitionTest.logger.debug('Token data found: "%s"' % (data))
     LexerStateTransitionTest.logger.debug('New buffer: %s' % (str(new_buffer)))
     LexerStateTransitionTest.logger.debug('Final stream state:\n%s' % (stream.to_pretty_json()))
     
     return (data, new_buffer)