Skip to content
Browse files

Add rules for Python-specific string literals

  • Loading branch information...
1 parent c0bee1f commit ddf0b92f5a5d315f2db3d27988c0f84dc4379cbf @kana committed Apr 7, 2012
Showing with 52 additions and 0 deletions.
  1. +12 −0 autoload/smartinput.vim
  2. +40 −0 t/api.vim
View
12 autoload/smartinput.vim
@@ -148,6 +148,15 @@ function! smartinput#define_default_rules() "{{{2
\ {'at': '\%#', 'char': '''', 'input': '''''<Left>',
\ 'syntax': ['Constant']},
\ ])
+ " Unfortunately, the space beyond the end of a comment line is not
+ " highlighted as 'Comment'. So that it is necessary to define one more rule
+ " to cover the edge case with only 'at'.
+ call urules.add('Python string', [
+ \ {'at': '\v\c<([bu]|[bu]?r)>%#', 'char': '''', 'input': '''''<Left>'},
+ \ {'at': '\v\c<([bu]|[bu]?r)>%#', 'char': '''', 'input': '''',
+ \ 'syntax': ['Comment', 'Constant']},
+ \ {'at': '\v\c\#.*<([bu]|[bu]?r)>%#$', 'char': '''', 'input': ''''},
+ \ ])
call urules.add('Vim script comment', [
\ {'at': '^\s*\%#', 'char': '"', 'input': '"'},
\ ])
@@ -179,6 +188,9 @@ function! smartinput#define_default_rules() "{{{2
\ 'perl': [
\ urules.table[''''' as strong quote'],
\ ],
+ \ 'python': [
+ \ urules.table['Python string'],
+ \ ],
\ 'ruby': [
\ urules.table[''''' as strong quote'],
\ ],
View
40 t/api.vim
@@ -1122,4 +1122,44 @@ describe 'The default configuration'
endfor
endfor
end
+
+ it 'should have rules for Python-specific string literals'
+ setfiletype python
+
+ let test_set_table = {}
+ for prefix in ['r', 'R',
+ \ 'b', 'B', 'br', 'bR', 'Br', 'BR',
+ \ 'u', 'U', 'ur', 'uR', 'Ur', 'UR']
+ let test_set_table[printf('%s''...'' in code', prefix)] = [
+ \ [prefix . "", [prefix . ''], 1, len(prefix) + 1 - 1],
+ \ ["'", [prefix . ''''''], 1, len(prefix) + 2 - 1],
+ \ ["x", [prefix . '''x'''], 1, len(prefix) + 3 - 1],
+ \ ]
+ let test_set_table[printf('%s''...'' in string', prefix)] = [
+ \ ["\"", ['""'], 1, 1 + 1 - 1],
+ \ [prefix . "", ['"' . prefix . '"'], 1, 1 + len(prefix) + 1 - 1],
+ \ ["'", ['"' . prefix . '''"'], 1, 1 + len(prefix) + 1 + 1 - 1],
+ \ ["x", ['"' . prefix . '''x"'], 1, 1 + len(prefix) + 2 + 1 - 1],
+ \ ]
+ let test_set_table[printf('%s''...'' in comment (middle)', prefix)] = [
+ \ ["# $\<Left>", ['# $'], 1, 2 + 1 - 1],
+ \ [prefix . "", ['# ' . prefix . '$'], 1, 2 + len(prefix) + 1 - 1],
+ \ ["'", ['# ' . prefix . '''$'], 1, 2 + len(prefix) + 1 + 1 - 1],
+ \ ["x", ['# ' . prefix . '''x$'], 1, 2 + len(prefix) + 2 + 1 - 1],
+ \ ]
+ let test_set_table[printf('%s''...'' in comment (EOL)', prefix)] = [
+ \ ["foo # ", ['foo # '], 1, 6 + 1 - 1],
+ \ [prefix . "", ['foo # ' . prefix . ''], 1, 6 + len(prefix) + 1 - 1],
+ \ ["'", ['foo # ' . prefix . ''''], 1, 6 + len(prefix) + 1 + 1 - 1],
+ \ ["x", ['foo # ' . prefix . '''x'], 1, 6 + len(prefix) + 2 + 1 - 1],
+ \ ]
+ endfor
+ let test_set_table['Typical comment'] = [
+ \ ["# You", ['# You'], 1, 6 - 1],
+ \ ["'", ['# You'''], 1, 7 - 1],
+ \ ["re", ['# You''re'], 1, 9 - 1],
+ \ ]
+
+ call b:.test_rules(test_set_table)
+ end
end

0 comments on commit ddf0b92

Please sign in to comment.
Something went wrong with that request. Please try again.