def MatchingSemanticTrigger_TriggerBetweenWords_test(): triggers = [cu._PrepareTrigger('.')] assert_that(cu._MatchingSemanticTrigger('foo . bar', 6, 9, triggers), none()) assert_that(cu._MatchingSemanticTrigger('foo . bar', 5, 9, triggers), re.escape('.')) assert_that(cu._MatchingSemanticTrigger('foo . bar', 4, 9, triggers), re.escape('.'))
def PreparedTriggers_Basic_test(): triggers = cu.PreparedTriggers() ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 8, 'c' ) ) eq_( triggers.MatchingTriggerForFiletype( 'foo.bar', 4, 8, 'c' ).pattern, re.escape( '.' ) ) ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 9, 'cpp' ) ) eq_( triggers.MatchingTriggerForFiletype( 'foo->bar', 5, 9, 'cpp' ).pattern, re.escape( '->' ) )
def PreparedTriggers_Basic_test(): triggers = cu.PreparedTriggers() assert_that(triggers.MatchesForFiletype('foo.bar', 4, 8, 'c')) assert_that( triggers.MatchingTriggerForFiletype('foo.bar', 4, 8, 'c').pattern, equal_to(re.escape('.'))) assert_that(triggers.MatchesForFiletype('foo->bar', 5, 9, 'cpp')) assert_that( triggers.MatchingTriggerForFiletype('foo->bar', 5, 9, 'cpp').pattern, equal_to(re.escape('->')))
def PreparedTriggers_UserTriggers_test(): triggers = cu.PreparedTriggers(user_trigger_map={'c': ['->']}) assert_that(triggers.MatchesForFiletype('foo->bar', 5, 8, 'c')) assert_that( triggers.MatchingTriggerForFiletype('foo->bar', 5, 8, 'c').pattern, equal_to(re.escape('->')))
def MatchingSemanticTrigger_Basic_test(): triggers = [ cu._PrepareTrigger( '.' ), cu._PrepareTrigger( ';' ), cu._PrepareTrigger( '::' ) ] eq_( cu._MatchingSemanticTrigger( 'foo->bar', 5, 9, triggers ), None ) eq_( cu._MatchingSemanticTrigger( 'foo::bar', 5, 9, triggers ).pattern, re.escape( '::' ) )
def MatchingSemanticTrigger_JustTrigger_test(): triggers = [cu._PrepareTrigger('.')] assert_that(cu._MatchingSemanticTrigger('.', 2, 2, triggers), none()) assert_that(cu._MatchingSemanticTrigger('.', 1, 1, triggers), re.escape('.')) assert_that(cu._MatchingSemanticTrigger('.', 0, 0, triggers), none())
def MatchingSemanticTrigger_RegexTrigger_test(): triggers = [cu._PrepareTrigger(r're!\w+\.')] assert_that(cu._MatchingSemanticTrigger('foo.bar', 4, 8, triggers), re.escape(r'\w+\.')) assert_that(cu._MatchingSemanticTrigger('foo . bar', 5, 8, triggers), none())
def PreparedTriggers_UserTriggers_test(): triggers = cu.PreparedTriggers(user_trigger_map={'c': ['->']}) ok_(triggers.MatchesForFiletype('foo->bar', 5, 8, 'c')) eq_( triggers.MatchingTriggerForFiletype('foo->bar', 5, 8, 'c').pattern, re.escape('->'))
def PreparedTriggers_OnlySomeFiletypesSelected_test(): triggers = cu.PreparedTriggers(filetype_set=set('c')) ok_(triggers.MatchesForFiletype('foo.bar', 4, 7, 'c')) eq_( triggers.MatchingTriggerForFiletype('foo.bar', 4, 7, 'c').pattern, re.escape('.')) ok_(not triggers.MatchesForFiletype('foo->bar', 5, 8, 'cpp')) eq_(triggers.MatchingTriggerForFiletype('foo->bar', 5, 8, 'cpp'), None)
def PreparedTriggers_OnlySomeFiletypesSelected_test(): triggers = cu.PreparedTriggers( filetype_set = set( 'c' ) ) ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 7, 'c' ) ) eq_( triggers.MatchingTriggerForFiletype( 'foo.bar', 4, 7, 'c' ).pattern, re.escape( '.' ) ) ok_( not triggers.MatchesForFiletype( 'foo->bar', 5, 8, 'cpp' ) ) eq_( triggers.MatchingTriggerForFiletype( 'foo->bar', 5, 8, 'cpp' ), None )
def PreparedTriggers_OnlySomeFiletypesSelected_test(): triggers = cu.PreparedTriggers(filetype_set=set('c')) assert_that(triggers.MatchesForFiletype('foo.bar', 4, 7, 'c')) assert_that( triggers.MatchingTriggerForFiletype('foo.bar', 4, 7, 'c').pattern, equal_to(re.escape('.'))) assert_that(not triggers.MatchesForFiletype('foo->bar', 5, 8, 'cpp')) assert_that(triggers.MatchingTriggerForFiletype('foo->bar', 5, 8, 'cpp'), none())
def MatchingSemanticTrigger_Basic_test(): triggers = [ cu._PrepareTrigger( '.' ), cu._PrepareTrigger( ';' ), cu._PrepareTrigger( '::' ) ] assert_that( cu._MatchingSemanticTrigger( 'foo->bar', 5, 9, triggers ), none() ) assert_that( cu._MatchingSemanticTrigger( 'foo::bar', 5, 9, triggers ).pattern, equal_to( re.escape( '::' ) ) )
def GetCompiledHeadRegexForDirectory(self, directory): mtime = GetModificationTime(directory) try: head_regex = self._head_path_for_directory[directory] if mtime and mtime <= head_regex['mtime']: return head_regex['regex'] except KeyError: pass current_paths = ListDirectory(directory) current_paths_pattern = '|'.join( [re.escape(path) for path in current_paths]) head_pattern = ('(' + self._head_path_pattern + '|' + current_paths_pattern + ')$') head_regex = re.compile(head_pattern, re.VERBOSE) if mtime: self._head_path_for_directory[directory] = { 'regex': head_regex, 'mtime': mtime } return head_regex
def GetCompiledHeadRegexForDirectory( self, directory ): mtime = GetModificationTime( directory ) try: head_regex = self._head_path_for_directory[ directory ] if mtime and mtime <= head_regex[ 'mtime' ]: return head_regex[ 'regex' ] except KeyError: pass current_paths = ListDirectory( directory ) current_paths_pattern = '|'.join( [ re.escape( path ) for path in current_paths ] ) head_pattern = ( '(' + self._head_path_pattern + '|' + current_paths_pattern + ')$' ) head_regex = re.compile( head_pattern, re.VERBOSE ) if mtime: self._head_path_for_directory[ directory ] = { 'regex': head_regex, 'mtime': mtime } return head_regex
def PrepareTrigger_UnicodeTrigger_Test(): regex = cu._PrepareTrigger( 'æ' ) assert_that( regex.pattern, equal_to( re.escape( u'æ' ) ) )
def _PrepareTrigger( trigger ): trigger = ToUnicode( trigger ) if trigger.startswith( TRIGGER_REGEX_PREFIX ): return re.compile( trigger[ len( TRIGGER_REGEX_PREFIX ) : ], re.UNICODE ) return re.compile( re.escape( trigger ), re.UNICODE )
def PrepareTrigger_UnicodeTrigger_Test(): regex = cu._PrepareTrigger( 'æ' ) eq_( regex.pattern, re.escape( u'æ' ) )
def PreparedTriggers_UserTriggers_test(): triggers = cu.PreparedTriggers( user_trigger_map = { 'c': [ '->' ] } ) ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 8, 'c' ) ) eq_( triggers.MatchingTriggerForFiletype( 'foo->bar', 5, 8, 'c' ).pattern, re.escape( '->' ) )
def PrepareTrigger_UnicodeTrigger_Test(): regex = cu._PrepareTrigger('æ') eq_(regex.pattern, re.escape(u'æ'))
def test_PrepareTrigger_UnicodeTrigger(self): regex = cu._PrepareTrigger('æ') assert_that(regex.pattern, equal_to(re.escape('æ')))