Permalink
Browse files

Merge branch 'support-for-python'

Close gh-35.
  • Loading branch information...
2 parents 895fc9a + ddf0b92 commit 40995692f00fcc978d2bb42b281292085a405687 @kana committed Apr 6, 2012
Showing with 88 additions and 103 deletions.
  1. +12 −0 autoload/smartinput.vim
  2. +76 −103 t/api.vim
View
@@ -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
179 t/api.vim
@@ -505,7 +505,7 @@ describe 'The default configuration'
new
setlocal autoindent
- function! b:.test_rules(test_set_names)
+ function! b:.test_rules(test_set_table)
" NB: [WHAT_MAP_EXPR_CAN_SEE] For some reason, ":normal SLet's" doesn't
" work as I expected. When "'" is being inserted with the command,
" s:_trigger_or_fallback is called with the following context:
@@ -524,8 +524,8 @@ describe 'The default configuration'
" So that the expected rule ("at" ==# '\w\%#') is selected.
"
" To avoid the problem, split :normal at the trigger character.
- for n in a:test_set_names
- let test_set = b:test_set_table[n]
+ for n in sort(keys(a:test_set_table))
+ let test_set = a:test_set_table[n]
% delete _
let i = 0 " For debugging.
for [input, lines, linenr, colnr] in test_set
@@ -536,8 +536,39 @@ describe 'The default configuration'
endfor
endfor
endfunction
+ end
+
+ after
+ close!
+ end
- let b:test_set_table = {
+ it 'should define necessary key mappings to trigger smart input assistants'
+ redir => s
+ 0 verbose imap
+ redir END
+ let lhss = split(s, '\n')
+ call map(lhss, 'substitute(v:val, ''\v\S+\s+(\S+)\s+.*'', ''\1'', ''g'')')
+ call sort(lhss)
+
+ Expect lhss ==# [
+ \ '"',
+ \ '''',
+ \ '(',
+ \ ')',
+ \ '<BS>',
+ \ '<C-H>',
+ \ '<CR>',
+ \ '<NL>',
+ \ '[',
+ \ ']',
+ \ '`',
+ \ '{',
+ \ '}',
+ \ ]
+ end
+
+ it 'should have generic rules for all filetypes'
+ call b:.test_rules({
\ '"" complete': [
\ ["\"", ['""'], 1, 2 - 1],
\ ],
@@ -900,105 +931,7 @@ describe 'The default configuration'
\ ["}", ['x{}'], 1, 4 - 1],
\ ["\<BS>", ['x'], 1, 2 - 1],
\ ],
- \ }
- end
-
- after
- close!
- end
-
- it 'should define necessary key mappings to trigger smart input assistants'
- redir => s
- 0 verbose imap
- redir END
- let lhss = split(s, '\n')
- call map(lhss, 'substitute(v:val, ''\v\S+\s+(\S+)\s+.*'', ''\1'', ''g'')')
- call sort(lhss)
-
- Expect lhss ==# [
- \ '"',
- \ '''',
- \ '(',
- \ ')',
- \ '<BS>',
- \ '<C-H>',
- \ '<CR>',
- \ '<NL>',
- \ '[',
- \ ']',
- \ '`',
- \ '{',
- \ '}',
- \ ]
- end
-
- it 'should have generic rules for all filetypes'
- call b:.test_rules([
- \ '() complete',
- \ '() escape',
- \ '() leave #1',
- \ '() leave #2',
- \ '() leave #3',
- \ '() leave #4',
- \ '() leave #5',
- \ '() undo #1',
- \ '() undo #2',
- \ '[] complete',
- \ '[] escape',
- \ '[] leave #1',
- \ '[] leave #2',
- \ '[] leave #3',
- \ '[] leave #4',
- \ '[] leave #5',
- \ '[] undo #1',
- \ '[] undo #2',
- \ '{} complete',
- \ '{} escape',
- \ '{} leave #1',
- \ '{} leave #2',
- \ '{} leave #3',
- \ '{} leave #4',
- \ '{} leave #5',
- \ '{} undo #1',
- \ '{} undo #2',
- \ ''''' complete',
- \ ''''' escape #1',
- \ ''''' escape #2',
- \ ''''' leave #1',
- \ ''''' leave #2',
- \ ''''' undo #1',
- \ ''''' undo #2',
- \ ''''''' complete',
- \ ''''''' leave #1',
- \ ''''''' leave #2',
- \ ''''''' undo #1',
- \ ''''''' undo #2',
- \ '"" complete',
- \ '"" escape #1',
- \ '"" escape #2',
- \ '"" leave #1',
- \ '"" leave #2',
- \ '"" undo #1',
- \ '"" undo #2',
- \ '""" complete',
- \ '""" leave #1',
- \ '""" leave #2',
- \ '""" undo #1',
- \ '""" undo #2',
- \ '`` complete',
- \ '`` escape #1',
- \ '`` escape #2',
- \ '`` leave #1',
- \ '`` leave #2',
- \ '`` undo #1',
- \ '`` undo #2',
- \ '``` complete',
- \ '``` leave #1',
- \ '``` leave #2',
- \ '``` undo #1',
- \ '``` undo #2',
- \ 'English',
- \ ])
+ \ })
end
it 'should have rules to write Lisp/Scheme source code'
@@ -1189,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 4099569

Please sign in to comment.