def test_ref_to_decorated_func(): def d(func): @wraps(func) def inner(): return func() inner.func = func return inner @d def boo(): return 1 r1 = ref(boo) @d def boo(): return 2 r2 = ref(boo) assert str(r1) == "vial.refs['tests.test_ref.boo:60']" assert r1() == 1 assert str(r2) == "vial.refs['tests.test_ref.boo:65']" assert r2() == 2
def test_ref_with_same_name(): refs.clear() def boo(): return 1 r1 = ref(boo) def boo(): return 2 r2 = ref(boo) assert r1() == 1 assert r2() == 2
def test_ref(): refs.clear() def boo(foo): return foo r = ref(boo) assert r(1) == 1 assert str(r) == 'vial.refs[\'tests.test_ref.boo:10\']'
def test_lazy_func(): refs.clear() r = ref('.test_ref.bar') assert r(10) == 10 assert str(r) == 'vial.refs[\'tests.test_ref.bar:lazy\']'
def test_lambda(): refs.clear() r = ref(lambda: 'boo') assert r() == 'boo' assert str(r) == 'vial.refs[\'tests.test_ref.<lambda>:35\']'
from vial import vim, ref win_buf_enter = ref('.plugin.win_buf_enter') jump = ref('.plugin.jump') def init(): vim.vars['vial_bufhist_timeout'] = 2 # seconds vim.vars['vial_bufhist_width'] = -20 vim.command('noremap <silent> <Plug>VialBufHistPrev :python %s(1)<cr>' % jump) vim.command('noremap <silent> <Plug>VialBufHistNext :python %s(-1)<cr>' % jump) vim.command('augroup VialBufHist') vim.command('autocmd!') vim.command('autocmd BufWinEnter * python %s()' % win_buf_enter) vim.command('augroup END')