diff --git a/plugin/extest.vim b/plugin/extest.vim index 9827a4d..d5c5e72 100644 --- a/plugin/extest.vim +++ b/plugin/extest.vim @@ -18,12 +18,14 @@ if !exists("extest_amrita_run_test_cmd") let s:extest_amrita_run_test_cmd = "mix amrita '%f:%l'" endif +" Exported commands command ExTestRunFile call RunFile() command ExTestRunTest call RunTest() command ExTestRunLast call RunLast() function s:RunFile() echo "RunFile called." + echo s:IdentifyFramework() endfunction function s:RunTest() @@ -33,3 +35,23 @@ endfunction function s:RunLast() echo "RunLast called." endfunction + +let s:framework_identifiers = {} +let s:framework_identifiers['^\s*test\s*"'] = "exunit" +let s:framework_identifiers['^\s*use ExUnit.Case\s*'] = "exunit" +let s:framework_identifiers['^\s*\(it\|fact\|facts\|describe\|context\|specify\) \s*'] = "amrita" +let s:framework_identifiers['^\s*use Amrita.Sweet\s*'] = "amrita" + +function s:IdentifyFramework() + let l:ln = a:firstline + while ln > 0 + let line = getline(l:ln) + for pattern in keys(s:framework_identifiers) + if line =~ pattern + return s:framework_identifiers[pattern] + endif + endfor + let l:ln -= 1 + endwhile + return 0 +endfunction