Beispiel #1
0
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('.'))
Beispiel #2
0
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( '->' ) )
Beispiel #3
0
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('->')))
Beispiel #6
0
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( '::' ) )
Beispiel #7
0
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())
Beispiel #8
0
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())
Beispiel #9
0
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( '::' ) )
Beispiel #10
0
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('->'))
Beispiel #11
0
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)
Beispiel #12
0
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())
Beispiel #14
0
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( '::' ) ) )
Beispiel #15
0
    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
Beispiel #16
0
  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
Beispiel #17
0
def PrepareTrigger_UnicodeTrigger_Test():
  regex = cu._PrepareTrigger( 'æ' )
  assert_that( regex.pattern, equal_to( re.escape( u'æ' ) ) )
Beispiel #18
0
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 )
Beispiel #19
0
def PrepareTrigger_UnicodeTrigger_Test():
  regex = cu._PrepareTrigger( 'æ' )
  eq_( regex.pattern, re.escape( u'æ' ) )
Beispiel #20
0
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( '->' ) )
Beispiel #21
0
def PrepareTrigger_UnicodeTrigger_Test():
    regex = cu._PrepareTrigger('æ')
    eq_(regex.pattern, re.escape(u'æ'))
Beispiel #22
0
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 )
Beispiel #23
0
 def test_PrepareTrigger_UnicodeTrigger(self):
     regex = cu._PrepareTrigger('æ')
     assert_that(regex.pattern, equal_to(re.escape('æ')))