Skip to content

Commit

Permalink
Add checks for empty identifiers and use + in regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Bijan Chokoufe Nejad committed May 7, 2016
1 parent f65c779 commit 71884f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ycmd/identifier_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@

# Spec: http://www.haskell.org/onlinereport/lexemes.html
# Section 2.4
'haskell': re.compile( r"[_a-zA-Z][\w']*", re.UNICODE ),
'haskell': re.compile( r"[_a-zA-Z][\w']+", re.UNICODE ),

# Spec: ?
# Labels like \label{fig:foobar} are very common
'tex': re.compile( r"[_a-zA-Z:-]*", re.UNICODE ),
'tex': re.compile( r"[_a-zA-Z:-]+", re.UNICODE ),

# Spec: http://doc.perl6.org/language/syntax
'perl6': re.compile( r"[_a-zA-Z](?:\w|[-'](?=[_a-zA-Z]))*", re.UNICODE ),
Expand Down
6 changes: 6 additions & 0 deletions ycmd/tests/identifier_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def IsIdentifier_Css_test():
ok_( not iu.IsIdentifier( '-3' , 'css' ) )
ok_( not iu.IsIdentifier( '3' , 'css' ) )
ok_( not iu.IsIdentifier( 'a' , 'css' ) )
ok_( not iu.IsIdentifier( '' , 'css' ) )


def IsIdentifier_R_test():
Expand All @@ -204,6 +205,7 @@ def IsIdentifier_R_test():
ok_( not iu.IsIdentifier( '123', 'r' ) )
ok_( not iu.IsIdentifier( '_1a', 'r' ) )
ok_( not iu.IsIdentifier( '_a' , 'r' ) )
ok_( not iu.IsIdentifier( '' , 'r' ) )


def IsIdentifier_Clojure_test():
Expand All @@ -229,6 +231,7 @@ def IsIdentifier_Clojure_test():
ok_( not iu.IsIdentifier( '9' , 'clojure' ) )
ok_( not iu.IsIdentifier( 'a/b/c', 'clojure' ) )
ok_( not iu.IsIdentifier( '(a)' , 'clojure' ) )
ok_( not iu.IsIdentifier( '' , 'clojure' ) )


def IsIdentifier_Haskell_test():
Expand All @@ -242,6 +245,7 @@ def IsIdentifier_Haskell_test():
ok_( not iu.IsIdentifier( "'x", 'haskell' ) )
ok_( not iu.IsIdentifier( "9x", 'haskell' ) )
ok_( not iu.IsIdentifier( "9" , 'haskell' ) )
ok_( not iu.IsIdentifier( '' , 'haskell' ) )


def IsIdentifier_Tex_test():
Expand All @@ -253,6 +257,7 @@ def IsIdentifier_Tex_test():

ok_( not iu.IsIdentifier( '\section', 'tex' ) )
ok_( not iu.IsIdentifier( 'some8', 'tex' ) )
ok_( not iu.IsIdentifier( '' , 'tex' ) )


def IsIdentifier_Perl6_test():
Expand All @@ -279,6 +284,7 @@ def IsIdentifier_Perl6_test():
ok_( not iu.IsIdentifier( "x+" , 'perl6' ) )
ok_( not iu.IsIdentifier( "9x" , 'perl6' ) )
ok_( not iu.IsIdentifier( "9" , 'perl6' ) )
ok_( not iu.IsIdentifier( '' , 'perl6' ) )


def StartOfLongestIdentifierEndingAtIndex_Simple_test():
Expand Down

0 comments on commit 71884f4

Please sign in to comment.