Created
April 6, 2016 16:30
-
-
Save junegunn/bcc10c7505b387b7338fcf9db8eb1f43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/autoload/vader/parser.vim b/autoload/vader/parser.vim | |
index dbf5da0..da7c7b8 100644 | |
--- a/autoload/vader/parser.vim | |
+++ b/autoload/vader/parser.vim | |
@@ -58,6 +58,9 @@ function! s:flush_buffer(cases, case, fn, lnum, raw, label, newlabel, buffer, fi | |
if a:final || | |
\ a:newlabel == 'given' || | |
\ index(['before', 'after', 'do', 'execute'], a:newlabel) >= 0 && fulfilled | |
+ if !empty(a:case.file) | |
+ let a:case.given = remove(a:case, 'file') | |
+ endif | |
call add(a:cases, deepcopy(a:case)) | |
let new = { 'comment': {}, 'lnum': a:lnum, 'pending': 0 } | |
if !empty(get(a:case, 'type', '')) | |
@@ -111,6 +114,16 @@ function! s:read_vader(fn, line1, line2) | |
return lines | |
endfunction | |
+function! s:matchany(str, patterns) | |
+ for pattern in a:patterns | |
+ let m = matchlist(a:str, pattern) | |
+ if !empty(m) | |
+ return m | |
+ endif | |
+ endfor | |
+ return [] | |
+endfunction | |
+ | |
function! s:parse_vader(lines, line1) | |
let label = '' | |
let newlabel = '' | |
@@ -125,35 +138,31 @@ function! s:parse_vader(lines, line1) | |
continue | |
endif | |
- let matched = 0 | |
- for l in ['Before', 'After', 'Given', 'Execute', 'Expect', 'Do', 'Then'] | |
- let m = matchlist(line, '^'.l.'\%(\s\+\([^:;(]\+\)\)\?\s*\%((\(.*\))\)\?\s*\([:;]\)\s*$') | |
- if !empty(m) | |
- let newlabel = tolower(l) | |
- call s:flush_buffer(cases, case, fn, lnum, m[3] == ';', label, newlabel, buffer, 0) | |
- | |
- let label = newlabel | |
- let arg = m[1] | |
- let comment = m[2] | |
- if !empty(arg) | |
- if l == 'Given' | let case.type = arg | |
- elseif l == 'Execute' | let case.lang_if = arg | |
- end | |
- elseif l == 'Given' | |
- let case.type = '' | |
- endif | |
- if !empty(comment) | |
- let case.comment[tolower(l)] = comment | |
- if index(['do', 'execute'], label) >= 0 && | |
- \ comment =~# '\<TODO\>\|\<FIXME\>' | |
- let case.pending = 1 | |
- endif | |
+ let m = s:matchany(line, | |
+ \ ['^\(Before\|After\|Given\|Execute\|Expect\|Do\|Then\)\%(\s\+\([^:;( ]\+\)\)\?\s*\%((\(.*\))\)\?\s*\([:;]\)\s*$', | |
+ \ '^\(Given\)\%(\s\+\([^:;(]\+\)\)\?\s*\%((\(.*\))\)\?\s*\([:;]\)\s*\(\S\+\)$']) | |
+ if !empty(m) | |
+ let newlabel = tolower(m[1]) | |
+ call s:flush_buffer(cases, case, fn, lnum, m[4] == ';', label, newlabel, buffer, 0) | |
+ | |
+ let label = newlabel | |
+ let arg = m[2] | |
+ let comment = m[3] | |
+ if label == 'given' | |
+ let case.type = arg | |
+ let case.file = m[5] | |
+ elseif label == 'execute' && !empty(arg) | |
+ let case.lang_if = arg | |
+ endif | |
+ if !empty(comment) | |
+ let case.comment[label] = comment | |
+ if index(['do', 'execute'], label) >= 0 && | |
+ \ comment =~# '\<TODO\>\|\<FIXME\>' | |
+ let case.pending = 1 | |
endif | |
- let matched = 1 | |
- break | |
endif | |
- endfor | |
- if matched | continue | endif | |
+ continue | |
+ endif | |
" Continuation | |
if !empty(line) && !case.raw && line !~ '^ ' | |
diff --git a/autoload/vader/window.vim b/autoload/vader/window.vim | |
index 2820acb..da664bd 100644 | |
--- a/autoload/vader/window.vim | |
+++ b/autoload/vader/window.vim | |
@@ -101,18 +101,25 @@ endfunction | |
function! vader#window#prepare(lines, type) | |
call s:switch_to_workbench() | |
- execute 'setlocal modifiable filetype='.a:type | |
+ if type(a:lines) == type('') | |
+ " TBD: Do we have to 'bd' buffers on cleanup? | |
+ execute 'e' a:lines | |
+ execute 'setlocal filetype='.a:type | |
+ else | |
+ execute 'setlocal modifiable filetype='.a:type | |
- %d _ | |
- for line in a:lines | |
- call append(line('$') - 1, line) | |
- endfor | |
- normal! "_ddgg | |
+ %d _ | |
+ for line in a:lines | |
+ call append(line('$') - 1, line) | |
+ endfor | |
+ normal! "_ddgg | |
+ endif | |
let &undolevels = &undolevels " Break undo block | |
endfunction | |
function! vader#window#cleanup() | |
+ execute s:workbench_tab.'tabclose' | |
execute 'silent! bd' s:workbench_bfr | |
call s:switch_to_console() | |
setlocal nomodifiable | |
diff --git a/syntax/vader.vim b/syntax/vader.vim | |
index fc4165d..1f37154 100644 | |
--- a/syntax/vader.vim | |
+++ b/syntax/vader.vim | |
@@ -49,6 +49,7 @@ syn match vaderSepSingle /^-.*/ contains=Todo | |
syn match vaderSepAsterisk /^\*.*/ contains=Todo | |
syn cluster vaderIgnored contains=vaderComment,vaderSepCaret,vaderSepTilde,vaderSepDouble,vaderSepSingle,vaderSepAsterisk | |
+syn match vaderGivenFile /^Given\(\s*(.*)\)\?\s*:\s*\ze\S\+$/ | |
syn region vaderGiven start=/^Given\(\s*(.*)\)\?\s*:\s*$/ end=/\(^[^ "^#~=*-]\)\@=/ contains=vaderMessage,vaderText,vaderComment,@vaderIgnored nextgroup=@vaderTopLevel skipempty | |
syn region vaderExpect start=/^Expect\(\s*(.*)\)\?\s*:\s*$/ end=/\(^[^ "^#~=*-]\)\@=/ contains=vaderMessage,vaderText,vaderComment,@vaderIgnored nextgroup=@vaderTopLevel skipempty | |
syn region vaderDo start=/^Do\(\s*(.*)\)\?\s*:\s*$/ end=/\(^[^ "^#~=*-]\)\@=/ contains=vaderMessage,vaderCommand,vaderComment,@vaderIgnored nextgroup=@vaderTopLevel skipempty | |
@@ -72,6 +73,7 @@ syn keyword Todo TODO FIXME XXX TBD | |
hi def link vaderInclude Repeat | |
hi def link vaderGiven Include | |
+hi def link vaderGivenFile Include | |
hi def link vaderGivenRaw Include | |
hi def link vaderBefore Special | |
hi def link vaderBeforeRaw Special |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment