Fix problems with merging vim.Dictionary

Also add tests

Fixes #516
This commit is contained in:
ZyX 2013-05-23 18:22:49 +04:00
parent 23a59ba93d
commit 9080a34ee8
6 changed files with 78 additions and 6 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ __pycache__
*.egg-info
dist
build
message.fail

View File

@ -17,6 +17,26 @@ if hasattr(vim, 'bindeval'):
return func
except vim.error:
return None
if hasattr(vim, 'Dictionary'):
VimDictionary = vim.Dictionary
VimList = vim.List
VimFunction = vim.Function
else:
VimDictionary = type(vim.bindeval('{}'))
VimList = type(vim.bindeval('[]'))
VimFunction = type(vim.bindeval('function("mode")'))
_vim_to_python_types = {
VimDictionary: lambda value: dict(((key, _vim_to_python(value[key])) for key in value.keys())),
VimList: lambda value: [_vim_to_python(item) for item in value],
VimFunction: lambda _: None,
}
_id = lambda value: value
def _vim_to_python(value):
return _vim_to_python_types.get(type(value), _id)(value)
else:
import json
@ -42,13 +62,13 @@ else:
if hasattr(vim, 'vars'):
def vim_getvar(varname):
return vim.vars[str(varname)]
return _vim_to_python(vim.vars[str(varname)])
elif hasattr(vim, 'bindeval'):
_vim_globals = vim.bindeval('g:')
def vim_getvar(varname): # NOQA
try:
return _vim_globals[str(varname)]
return _vim_to_python(_vim_globals[str(varname)])
except (KeyError, IndexError):
raise KeyError(varname)
else:

View File

@ -10,7 +10,12 @@ done
if ! ${PYTHON} scripts/powerline-lint -p powerline/config_files ; then
FAILED=1
fi
if ! vim -S tests/test_plugin_file.vim ; then
FAILED=1
fi
for script in tests/*.vim ; do
if ! vim -u NONE -S $script || test -f message.fail ; then
echo "Failed script $script" >&2
cat message.fail >&2
rm message.fail
FAILED=1
fi
done
exit $FAILED

38
tests/test_local_overrides.vim Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/vim -S
let g:powerline_config_path = expand('<sfile>:p:h:h') . '/powerline/config_files'
let g:powerline_config_overrides = {'common': {'dividers': {'left': {'hard': ' ', 'soft': ' > '}, 'right': {'hard': ' ', 'soft': ' < '}}}}
let g:powerline_theme_overrides__default = {'segment_data': {'line_current_symbol': {'contents': 'LN '}, 'branch': {'before': 'B '}}}
try
python import powerline.vim
let pycmd = 'python'
catch
try
python3 import powerline.vim
let pycmd = 'python3'
catch
call writefile(['Unable to determine python version', v:exception], 'message.fail')
cquit
endtry
endtry
try
execute pycmd 'powerline.vim.setup()'
catch
call writefile(['Failed to run setup function', v:exception], 'message.fail')
cquit
endtry
try
let &columns = 80
let result = eval(&statusline[2:])
catch
call writefile(['Exception while evaluating &stl', v:exception], 'message.fail')
cquit
endtry
if result isnot# '%#Pl_22_24320_148_11523840_bold# NORMAL %#Pl_148_11523840_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                                 %#Pl_247_10395294_236_3158064_NONE#unix%#Pl_240_5789784_236_3158064_NONE# %#Pl_160_15485749_240_5789784_NONE# 100%%%#Pl_252_13684944_240_5789784_NONE# %#Pl_235_2500134_252_13684944_NONE# LN %#Pl_235_2500134_252_13684944_bold#  1%#Pl_22_24320_252_13684944_NONE#:1  '
call writefile(['Unexpected result', result], 'message.fail')
cquit
endif
qall!

View File

@ -3,6 +3,7 @@ set nocompatible
try
source powerline/bindings/vim/plugin/powerline.vim
catch
call writefile([v:exception], 'message.fail')
cquit
endtry
set ls=2
@ -10,7 +11,9 @@ redrawstatus!
redir =>mes
messages
redir END
if len(split(mes, "\n"))>1
let mess=split(mes, "\n")
if len(mess)>1
call writefile(mess, 'message.fail')
cquit
endif
quit!

View File

@ -175,6 +175,10 @@ def eval(expr):
def bindeval(expr):
if expr == 'g:':
return vars
elif expr == '{}':
return {}
elif expr == '[]':
return []
import re
match = re.compile(r'^function\("([^"\\]+)"\)$').match(expr)
if match: