mirror of
https://github.com/amix/vimrc
synced 2025-07-10 03:25:00 +08:00
add Previm and window management
This commit is contained in:
2
sources_non_forked/previm/test/.vimrc
Normal file
2
sources_non_forked/previm/test/.vimrc
Normal file
@ -0,0 +1,2 @@
|
||||
" setting for kannokanno/vimtest
|
||||
let &runtimepath = expand('<sfile>:p:h:h')
|
210
sources_non_forked/previm/test/autoload/previm_test.vim
Normal file
210
sources_non_forked/previm/test/autoload/previm_test.vim
Normal file
@ -0,0 +1,210 @@
|
||||
let s:newline = "\\n"
|
||||
let s:assert = themis#helper('assert')
|
||||
|
||||
let s:t = themis#suite('convert_to_content') "{{{
|
||||
|
||||
function! s:t.empty_lines()
|
||||
let arg = []
|
||||
let expected = ''
|
||||
call s:assert.equals(previm#convert_to_content(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.not_exists_escaped()
|
||||
let arg = ['aaabbb', 'あいうえお漢字']
|
||||
let expected =
|
||||
\ 'aaabbb' . s:newline
|
||||
\ . 'あいうえお漢字'
|
||||
call s:assert.equals(previm#convert_to_content(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.exists_backslash()
|
||||
let arg = ['\(x -> x + 2)', 'あいうえお漢字']
|
||||
let expected =
|
||||
\ '\\(x -> x + 2)' . s:newline
|
||||
\ . 'あいうえお漢字'
|
||||
call s:assert.equals(previm#convert_to_content(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.exists_double_quotes()
|
||||
let arg = ['he said. "Hello, john"', 'あいうえお漢字']
|
||||
let expected =
|
||||
\ 'he said. \"Hello, john\"' . s:newline
|
||||
\ . 'あいうえお漢字'
|
||||
call s:assert.equals(previm#convert_to_content(arg), expected)
|
||||
endfunction
|
||||
"}}}
|
||||
let s:t = themis#suite('relative_to_absolute') "{{{
|
||||
|
||||
function! s:t.nothing_when_empty()
|
||||
let arg_line = ''
|
||||
let expected = ''
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, ''), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.nothing_when_not_href()
|
||||
let arg_line = 'previm.dummy.com/some/path/img.png'
|
||||
let expected = 'previm.dummy.com/some/path/img.png'
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, ''), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.nothing_when_absolute_by_http()
|
||||
let arg_line = 'http://previm.dummy.com/some/path/img.png'
|
||||
let expected = 'http://previm.dummy.com/some/path/img.png'
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, ''), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.nothing_when_absolute_by_https()
|
||||
let arg_line = 'https://previm.dummy.com/some/path/img.png'
|
||||
let expected = 'https://previm.dummy.com/some/path/img.png'
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, ''), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.nothing_when_absolute_by_file()
|
||||
let arg_line = 'file://previm/some/path/img.png'
|
||||
let expected = 'file://previm/some/path/img.png'
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, ''), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.replace_path_when_relative()
|
||||
let rel_path = 'previm/some/path/img.png'
|
||||
let arg_line = printf('', rel_path)
|
||||
let arg_dir = '/Users/foo/tmp'
|
||||
let expected = printf('', arg_dir, rel_path)
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, arg_dir), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.urlencoded_path()
|
||||
let rel_path = 'previm\some\path\img.png'
|
||||
let arg_line = printf('', rel_path)
|
||||
let arg_dir = 'C:\Documents and Settings\folder'
|
||||
let expected = ''
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, arg_dir), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.with_title_from_double_quote()
|
||||
let rel_path = 'previm\some\path\img.png'
|
||||
let arg_line = printf('', rel_path)
|
||||
let arg_dir = 'C:\Documents and Settings\folder'
|
||||
let expected = ''
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, arg_dir), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.with_title_from_single_quote()
|
||||
let rel_path = 'previm\some\path\img.png'
|
||||
let arg_line = printf("", rel_path)
|
||||
let arg_dir = 'C:\Documents and Settings\folder'
|
||||
let expected = ''
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, arg_dir), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.not_only_img()
|
||||
let rel_path = 'previm/some/path/img.png'
|
||||
let arg_line = printf('| a |  |', rel_path)
|
||||
let arg_dir = '/Users/foo/tmp'
|
||||
let expected = printf('| a |  |', arg_dir, rel_path)
|
||||
call s:assert.equals(previm#relative_to_absolute_imgpath(arg_line, arg_dir), expected)
|
||||
endfunction
|
||||
"}}}
|
||||
let s:t = themis#suite('fetch_imgpath_elements') "{{{
|
||||
|
||||
function! s:t.nothing_when_empty()
|
||||
let arg = ''
|
||||
let expected = s:empty_img_elements()
|
||||
call s:assert.equals(previm#fetch_imgpath_elements(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.nothing_when_not_img_statement()
|
||||
let arg = '## hogeほげ'
|
||||
let expected = s:empty_img_elements()
|
||||
call s:assert.equals(previm#fetch_imgpath_elements(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.get_alt_and_path()
|
||||
let arg = ''
|
||||
let expected = {'alt': 'IMG', 'path': 'path/img.png', 'title': ''}
|
||||
call s:assert.equals(previm#fetch_imgpath_elements(arg), expected)
|
||||
endfunction
|
||||
|
||||
function! s:t.get_title_from_double_quote()
|
||||
let arg = ''
|
||||
let expected = {'alt': 'IMG', 'path': 'path/img.png', 'title': 'image'}
|
||||
call s:assert.equals(expected, previm#fetch_imgpath_elements(arg))
|
||||
endfunction
|
||||
|
||||
function! s:t.get_title_from_single_quote()
|
||||
let arg = ""
|
||||
let expected = {'alt': 'IMG', 'path': 'path/img.png', 'title': 'image'}
|
||||
call s:assert.equals(expected, previm#fetch_imgpath_elements(arg))
|
||||
endfunction
|
||||
|
||||
function! s:empty_img_elements()
|
||||
return {'alt': '', 'path': '', 'title': ''}
|
||||
endfunction
|
||||
"}}}
|
||||
let s:t = themis#suite('refresh_css') "{{{
|
||||
function! s:t.setup()
|
||||
let self.exist_previm_disable_default_css = 0
|
||||
if exists('g:previm_disable_default_css')
|
||||
let self.tmp_previm_disable_default_css = g:previm_disable_default_css
|
||||
let self.exist_previm_disable_default_css = 1
|
||||
endif
|
||||
|
||||
let self.exist_previm_custom_css_path = 0
|
||||
if exists('g:previm_custom_css_path')
|
||||
let self.tmp_previm_custom_css_path = g:previm_custom_css_path
|
||||
let self.exist_previm_custom_css_path = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:t.teardown()
|
||||
if self.exist_previm_disable_default_css
|
||||
let g:previm_disable_default_css = self.tmp_previm_disable_default_css
|
||||
else
|
||||
unlet! g:previm_disable_default_css
|
||||
endif
|
||||
|
||||
if self.exist_previm_custom_css_path
|
||||
let g:previm_custom_css_path = self.tmp_previm_custom_css_path
|
||||
else
|
||||
unlet! g:previm_custom_css_path
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:t.default_content_if_not_exists_setting()
|
||||
call previm#refresh_css()
|
||||
let actual = readfile(previm#make_preview_file_path('css/previm.css'))
|
||||
call s:assert.equals([
|
||||
\ "@import url('origin.css');",
|
||||
\ "@import url('lib/github.css');",
|
||||
\ ], actual)
|
||||
endfunction
|
||||
|
||||
function! s:t.default_content_if_invalid_setting()
|
||||
let g:previm_disable_default_css = 2
|
||||
call previm#refresh_css()
|
||||
let actual = readfile(previm#make_preview_file_path('css/previm.css'))
|
||||
call s:assert.equals([
|
||||
\ "@import url('origin.css');",
|
||||
\ "@import url('lib/github.css');",
|
||||
\ ], actual)
|
||||
endfunction
|
||||
|
||||
let s:base_dir = expand('<sfile>:p:h')
|
||||
function! s:t.custom_content_if_exists_file()
|
||||
let g:previm_disable_default_css = 1
|
||||
let g:previm_custom_css_path = s:base_dir . '/dummy_user_custom.css'
|
||||
call previm#refresh_css()
|
||||
|
||||
let actual = readfile(previm#make_preview_file_path('css/previm.css'))
|
||||
call s:assert.equals(actual, ["@import url('user_custom.css');"])
|
||||
endfunction
|
||||
|
||||
function! s:t.empty_if_not_exists_file()
|
||||
let g:previm_disable_default_css = 1
|
||||
let g:previm_custom_css_path = s:base_dir . '/not_exists.css'
|
||||
call previm#refresh_css()
|
||||
|
||||
let actual = readfile(previm#make_preview_file_path('css/previm.css'))
|
||||
call s:assert.equals(actual, [])
|
||||
endfunction
|
||||
"}}}
|
46
sources_non_forked/previm/test/plugin/previm_test.vim
Normal file
46
sources_non_forked/previm/test/plugin/previm_test.vim
Normal file
@ -0,0 +1,46 @@
|
||||
let s:t = themis#suite('valid filetype for using :PrevimOpen')
|
||||
let s:assert = themis#helper('assert')
|
||||
|
||||
function! s:t.before()
|
||||
let self._ft = &filetype
|
||||
endfunction
|
||||
|
||||
function! s:t.after()
|
||||
let &filetype = self._ft
|
||||
call s:_clean_command()
|
||||
endfunction
|
||||
|
||||
function! s:_clean_command()
|
||||
if exists(':PrevimOpen') == 2
|
||||
delcommand PrevimOpen
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" helper
|
||||
function! s:_assert_filetype(ft, expected)
|
||||
let &filetype = a:ft
|
||||
let actual = exists(':PrevimOpen')
|
||||
if actual !=# a:expected
|
||||
call s:assert.fail(printf("'%s': expected %d but actual %d", a:ft, a:expected, actual))
|
||||
endif
|
||||
endfunction
|
||||
"""
|
||||
|
||||
function! s:t.invalid_filetype()
|
||||
let not_exist_command = 0
|
||||
for type in ['', 'rb', 'php']
|
||||
call s:_assert_filetype(type, not_exist_command)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:t.valid_filetype()
|
||||
let exist_command = 2
|
||||
for type in [
|
||||
\ 'markdown', 'mkd', 'rst', 'textile',
|
||||
\ 'aaa.markdown', 'mkd.foo', 'bb.rst.cc', 'a.b.c.textile',
|
||||
\]
|
||||
call s:_assert_filetype(type, exist_command)
|
||||
call s:_clean_command()
|
||||
endfor
|
||||
endfunction
|
||||
|
Reference in New Issue
Block a user