@@ -19,75 +19,116 @@ function! s:CallProcessor(event, args) abort
19
19
endfor
20
20
endfunction
21
21
22
- function ultest#process#new (test) abort
23
- call ultest#process#pre (a: test )
24
- if index (g: ultest_buffers , a: test .file ) == -1
25
- let g: ultest_buffers = add (g: ultest_buffers , a: test .file )
26
- endif
27
- let tests = getbufvar (a: test .file , " ultest_tests" , {})
28
- let tests[a: test .id] = a: test
29
- call s: CallProcessor (" new" , [a: test ])
22
+ function ! s: UpdateBufferTests (tests) abort
23
+ let new_tests = {}
24
+ for test in a: tests
25
+ if index (g: ultest_buffers , test.file ) == -1
26
+ let g: ultest_buffers = add (g: ultest_buffers , test.file )
27
+ endif
28
+ if ! has_key (new_tests, test.file )
29
+ let new_tests[test.file ] = {}
30
+ endif
31
+ let new_tests[test.file ][test.id] = test
32
+ endfor
33
+ for [file , new_file_tests] in items (new_tests)
34
+ let tests = getbufvar (file , " ultest_tests" , {})
35
+ call extend (tests, new_file_tests)
36
+ endfor
30
37
endfunction
31
38
32
- function ultest#process#start (test) abort
33
- call ultest#process#pre (a: test )
34
- let tests = getbufvar (a: test .file , " ultest_tests" , {})
35
- let tests[a: test .id] = a: test
36
- let results = getbufvar (a: test .file , " ultest_results" )
37
- if has_key (results, a: test .id)
38
- call remove (results, a: test .id)
39
- endif
40
- call s: CallProcessor (" start" , [a: test ])
39
+ function ! s: UpdateBufferResults (results) abort
40
+ let new_results = {}
41
+ for result in a: results
42
+ if ! has_key (new_results, result.file )
43
+ let new_results[result.file ] = {}
44
+ endif
45
+ let new_results[result.file ][result.id] = result
46
+ endfor
47
+ for [file , new_file_results] in items (new_results)
48
+ let tests = getbufvar (file , " ultest_results" , {})
49
+ call extend (tests, new_file_results)
50
+ endfor
41
51
endfunction
42
52
43
- function ultest#process#move (test) abort
44
- call ultest#process#pre (a: test )
45
- let tests = getbufvar (a: test .file , " ultest_tests" )
46
- let tests[a: test .id] = a: test
47
- call s: CallProcessor (" move" , [a: test ])
53
+ function ! s: ClearTests (tests) abort
54
+ for test in a: tests
55
+ let buf_tests = getbufvar (test.file , " ultest_tests" )
56
+ if has_key (buf_tests, test.id)
57
+ call remove (buf_tests, test.id)
58
+ endif
59
+ endfor
48
60
endfunction
49
61
50
- function ultest#process#replace (test, result ) abort
51
- call ultest#process#pre ( a: test )
52
- let tests = getbufvar (a: test .file , " ultest_tests " )
53
- let tests[ a: test .id] = a: test
54
- let results = getbufvar ( a: result . file , " ultest_results " )
55
- let results[ a: result .id] = a: result
56
- call s: CallProcessor ( " replace " , [ a: result ])
62
+ function ! s: ClearTestResults (tests ) abort
63
+ for test in a: tests
64
+ let results = getbufvar (test.file , " ultest_results " )
65
+ if has_key (results, test.id)
66
+ call remove (results, test.id )
67
+ endif
68
+ endfor
57
69
endfunction
58
70
59
- function ultest#process#clear (test) abort
60
- call ultest#process#pre (a: test )
61
- let tests = getbufvar (a: test .file , " ultest_tests" )
62
- if has_key (tests, a: test .id)
63
- call remove (tests, a: test .id)
64
- endif
65
- let results = getbufvar (a: test .file , " ultest_results" )
66
- if has_key (results, a: test .id)
67
- call remove (results, a: test .id)
68
- endif
69
- call s: CallProcessor (" clear" , [a: test ])
71
+ function ! s: SeparateTestAndResults (combined) abort
72
+ let tests = []
73
+ let results = []
74
+ for [test, result] in a: combined
75
+ call add (tests, test)
76
+ call add (results, result)
77
+ endfor
78
+ return [tests, results]
70
79
endfunction
71
80
72
- function ultest#process#exit (test, result) abort
73
- call ultest#process#pre (a: test )
74
- if ! has_key (getbufvar (a: result .file , " ultest_tests" , {}), a: result .id)
75
- return
76
- endif
77
- let tests = getbufvar (a: test .file , " ultest_tests" , {})
78
- let tests[a: test .id] = a: test
79
- let results = getbufvar (a: result .file , " ultest_results" )
80
- let results[a: result .id] = a: result
81
- call s: CallProcessor (" exit" , [a: result ])
81
+ function ultest#process#new (tests) abort
82
+ call ultest#process#pre (a: tests )
83
+ call s: UpdateBufferTests (a: tests )
84
+ call s: CallProcessor (" new" , [a: tests ])
85
+ endfunction
86
+
87
+ function ultest#process#start (tests) abort
88
+ call ultest#process#pre (a: tests )
89
+ call s: UpdateBufferTests (a: tests )
90
+ call s: ClearTestResults (a: tests )
91
+ call s: CallProcessor (" start" , [a: tests ])
92
+ endfunction
93
+
94
+ function ultest#process#move (tests) abort
95
+ call ultest#process#pre (a: tests )
96
+ call s: UpdateBufferTests (a: tests )
97
+ call s: CallProcessor (" move" , [a: tests ])
98
+ endfunction
99
+
100
+ function ultest#process#replace (combined) abort
101
+ let [tests, results] = s: SeparateTestAndResults (a: combined )
102
+ call ultest#process#pre (tests)
103
+ call s: UpdateBufferTests (tests)
104
+ call s: UpdateBufferResults (results)
105
+ call s: CallProcessor (" replace" , [results])
82
106
endfunction
83
107
84
- function ultest#process#pre (test) abort
85
- if type (a: test .name) == v: t_list
86
- if exists (" *list2str" )
87
- let newName = list2str (a: test .name)
88
- else
89
- let newName = join (map (a: test .name, {nr, val - > nr2char (val)}), ' ' )
108
+ function ultest#process#clear (tests) abort
109
+ call ultest#process#pre (a: tests )
110
+ call s: ClearTests (a: tests )
111
+ call s: ClearTestResults (a: tests )
112
+ call s: CallProcessor (" clear" , [a: tests ])
113
+ endfunction
114
+
115
+ function ultest#process#exit (combined) abort
116
+ let [tests, results] = s: SeparateTestAndResults (a: combined )
117
+ call ultest#process#pre (tests)
118
+ call s: UpdateBufferTests (tests)
119
+ call s: UpdateBufferResults (results)
120
+ call s: CallProcessor (" exit" , [results])
121
+ endfunction
122
+
123
+ function ultest#process#pre (tests) abort
124
+ for test in a: tests
125
+ if type (test.name) == v: t_list
126
+ if exists (" *list2str" )
127
+ let newName = list2str (test.name)
128
+ else
129
+ let newName = join (map (test.name, {nr, val - > nr2char (val)}), ' ' )
130
+ endif
131
+ let test.name = newName
90
132
endif
91
- let a: test .name = newName
92
- endif
133
+ endfor
93
134
endfunction
0 commit comments