@@ -4,163 +4,36 @@ set cpo&vim
44if exists (' g:JavaUnit_loaded' )
55 finish
66endif
7- let g: JavaUnit_loaded = 1
8-
9- let s: Fsep = javaunit#util#Fsep ()
10-
11- let s: Psep = javaunit#util#Psep ()
12-
13- let g: JavaUnit_Home = fnamemodify (expand (' <sfile>' ), ' :p:h:h:gs?\\?' . s: Fsep . ' ?' )
14-
15- if exists (" g:JavaUnit_custom_tempdir" )
16- let g: JavaUnit_tempdir = g: JavaUnit_custom_tempdir
17- else
18- let g: JavaUnit_tempdir = g: JavaUnit_Home .s: Fsep .' bin'
19- endif
20-
21- let s: JavaUnit_TestMethod_Source = g: JavaUnit_Home .s: Fsep .join ([' src' ,' com' ,' wsdjeg' ,' util' ,' TestMethod.java' ],s: Fsep )
22-
23- lockvar ! s: JavaUnit_TestMethod_Source g: JavaUnit_tempdir
24-
25- if findfile (g: JavaUnit_tempdir .join ([' ' ,' com' ,' wsdjeg' ,' util' ,' TestMethod.class' ],s: Fsep ))== " "
26- silent exec ' !javac -encoding utf8 -d "' .g: JavaUnit_tempdir .' " "' .s: JavaUnit_TestMethod_Source .' "'
27- endif
28-
29- function JaveUnitTestMethod (args ,... )
30- let line = getline (search (" package" ," nb" ,getline (" 0$" )))
31- if line != ' '
32- let currentClassName = split (split (line ," " )[1 ]," ;" )[0 ]." ." .expand (" %:t:r" )
33- else
34- let currentClassName = expand (" %:t:r" )
35- endif
36- if a: args == " "
37- let cwords = split (airline#extensions#tagbar#currenttag (),' (' )[0 ]
38- if filereadable (' pom.xml' )
39- let cmd= ' java -cp "'
40- \. g: JavaUnit_tempdir
41- \. s: Psep
42- \. getcwd ()
43- \. join ([' ' ,' target' ,' test-classes' ],s: Fsep )
44- \. s: Psep
45- \. get (g: ,' JavaComplete_LibsPath' ,' .' )
46- \. ' " com.wsdjeg.util.TestMethod '
47- \. currentClassName
48- \. ' '
49- \. cwords
50- else
51- let cmd= ' java -cp "'
52- \. g: JavaUnit_tempdir
53- \. s: Psep
54- \. get (g: ,' JavaComplete_LibsPath' ,' .' )
55- \. ' " com.wsdjeg.util.TestMethod '
56- \. currentClassName
57- \. ' '
58- \. cwords
59- endif
60- call unite#start ([[' output/shellcmd' , cmd]], {' log' : 1 , ' wrap' : 1 })
61- else
62- if filereadable (' pom.xml' )
63- let cmd= ' java -cp "'
64- \. g: JavaUnit_tempdir
65- \. s: Psep
66- \. getcwd ()
67- \. join ([' ' ,' target' ,' test-classes' ],s: Fsep )
68- \. s: Psep
69- \. get (g: ,' JavaComplete_LibsPath' ,' .' )
70- \. ' " com.wsdjeg.util.TestMethod '
71- \. currentClassName
72- \. ' '
73- \. a: args
74- else
75- let cmd= ' java -cp "'
76- \. g: JavaUnit_tempdir
77- \. s: Psep
78- \. get (g: ,' JavaComplete_LibsPath' ,' .' )
79- \. ' " com.wsdjeg.util.TestMethod '
80- \. currentClassName
81- \. ' '
82- \. a: args
83- endif
84- call unite#start ([[' output/shellcmd' , cmd]], {' log' : 1 , ' wrap' : 1 })
85- endif
86- endfunction
87-
88- function JavaUnitTestAllMethods ()
89- let line = getline (search (" package" ," nb" ,getline (" 0$" )))
90- let currentClassName = split (split (line ," " )[1 ]," ;" )[0 ]." ." .expand (" %:t:r" )
91- let cmd= ' java -cp "' .g: JavaUnit_tempdir .s: Psep .g: JavaComplete_LibsPath .' " com.wsdjeg.util.TestMethod ' .currentClassName
92- call unite#start ([[' output/shellcmd' , cmd]], {' log' : 1 , ' wrap' : 1 })
93- endfunction
947
95- function JavaUnitEscapeCMD (cmd)
96- let s: cmd = substitute (a: cmd ,' ' ,' \\ ' ,' g' )
97- let s: cmd = substitute (s: cmd ,' \' ,' \\\' ,' g' )
98- let s: cmd = substitute (s: cmd ,' ;' ,' \\;' ,' g' )
99- let s: cmd = substitute (s: cmd , ' \t' , ' \\t' , ' g' )
100- return substitute (s: cmd ,' :' ,' \\:' ,' g' )
101- endfunction
102-
103- function JavaUnitMavenTest ()
104- let line = getline (search (" package" ," nb" ,getline (" 0$" )))
105- let currentClassName = split (split (line ," " )[1 ]," ;" )[0 ]." ." .expand (" %:t:r" )
106- let cmd = ' mvn test -Dtest=' .currentClassName.' |ag --nocolor "^[^[]"'
107- call unite#start ([[' output/shellcmd' , cmd]], {' log' : 1 , ' wrap' : 1 })
108- endfunction
109-
110- function JavaUnitMavenTestAll ()
111- let cmd = ' mvn test|ag --nocolor "^[^[]"'
112- call unite#start ([[' output/shellcmd' , cmd]], {' log' : 1 , ' wrap' : 1 })
113- endfunction
114-
115- function JavaUnitNewClass (classNAME)
116- let filePath = expand (" %:h" )
117- let flag = 0
118- let packageName = ' '
119- for a in split (filePath,s: Fsep )
120- if flag
121- if a == expand (" %:h:t" )
122- let packageName .= a .' ;'
123- else
124- let packageName .= a .' .'
125- endif
126- endif
127- if a == " java"
128- let flag = 1
129- endif
130- endfor
131- call append (0 ," package " .packageName)
132- call append (1 ," import org.junit.Test;" )
133- call append (2 ," import org.junit.Assert;" )
134- call append (3 ," public class " .a: classNAME ." {" )
135- call append (4 ," @Test" )
136- call append (5 ," public void testM() {" )
137- call append (6 ," //TODO" )
138- call append (7 ," }" )
139- call append (8 ," }" )
140- call feedkeys (" gg=G" ," n" )
141- call feedkeys (" /testM\<cr> " ," n" )
142- call feedkeys (" viw" ," n" )
143- " call feedkeys("/TODO\<cr>","n")
144- endfunction
8+ let g: JavaUnit_loaded = 1
1459
14610command ! -nargs =*
14711 \ JavaUnitTest
148- \ call JaveUnitTestMethod (<q-args> )
12+ \ call javaunit#TestMethod (<q-args> )
13+
14914command ! -nargs =0
15015 \ JavaUnitExec
15116 \ call javaunit#TestMain ()
17+
15218command ! -nargs =0
15319 \ JavaUnitTestAll
154- \ call JavaUnitTestAllMethods ()
20+ \ call javaunit#TestAllMethods ()
21+
15522command ! -nargs =0
15623 \ JavaUnitTestMaven
157- \ call JavaUnitMavenTest ()
24+ \ call javaunit#MavenTest ()
25+
15826command ! -nargs =0
15927 \ JavaUnitTestMavenAll
160- \ call JavaUnitMavenTestAll ()
28+ \ call javaunit#MavenTestAll ()
29+
16130command ! -nargs =? -complete =file
162- \ JavaUnitTestNewClass
163- \ call JavaUnitNewClass (expand (" %:t:r" ))
31+ \ JavaUnitNewTestClass
32+ \ call javaunit#NewTestClass (expand (" %:t:r" ))
33+
34+ command ! -nargs =0
35+ \ JavaUnitCompile
36+ \ call javaunit#Compile ()
16437
16538let &cpo = s: save_cpo
16639unlet s: save_cpo
0 commit comments