CLI interface to medialist (fossil mirror)
修訂 | c1d9d4ea0b520b74c4bfdd259acde91f3fe17350 (tree) |
---|---|
時間 | 2021-11-13 17:35:56 |
作者 | mio <stigma@disr...> |
Commiter | mio |
Add a unittest for ticket 5b28c4e8174fb4dd
FossilOrigin-Name: e86c92b52f314e15f7d33676123c6c11e6f381d8500eabe87d9d979898b51df6
@@ -144,7 +144,7 @@ handle_update(string program_name, string[] args, string data_dir) | ||
144 | 144 | string oldStatus = ""; |
145 | 145 | |
146 | 146 | import std.array : replicate; |
147 | - | |
147 | + | |
148 | 148 | string currentDateString = currentDate.toISOExtString(); |
149 | 149 | |
150 | 150 | foreach (sectionIndent, section; sections) |
@@ -215,7 +215,7 @@ handle_update(string program_name, string[] args, string data_dir) | ||
215 | 215 | File f = File(filename, "w"); |
216 | 216 | foreach(l; contents) |
217 | 217 | if (0 != l.length) f.writeln(l); |
218 | - | |
218 | + | |
219 | 219 | stdout.writefln("Successfully updated %s (%s, %s)", title, status, progress); |
220 | 220 | |
221 | 221 | return true; |
@@ -248,3 +248,80 @@ example: | ||
248 | 248 | 10: Title -> COMPLETE -> 12/12", program_name, program_name, |
249 | 249 | program_name); |
250 | 250 | } |
251 | + | |
252 | +/* | |
253 | + * Ticket 5b28c4e8174fb4dd | |
254 | + * After creating a new list and adding a new item to it, calling subsequent modifications | |
255 | + * (e.g. update and delete) would cause the "new" headers to be removed. | |
256 | + * | |
257 | + * This issue occurred when the "start_date", "end_date", and "last_updated" headers were | |
258 | + * first added, so the previous code assumes the header line was TITLE\tSTATUS\tPROGRESS, | |
259 | + * while the new code shouldn't assume the position of anything. | |
260 | + */ | |
261 | +unittest | |
262 | +{ | |
263 | + /* | |
264 | + * I would like to make a "medialist library" so that you would | |
265 | + * call something like ml_list_create (MediaList*, string) to | |
266 | + * create a new list, but for now, we just "re-run" the program. | |
267 | + * | |
268 | + * Perhaps a command-based interface? | |
269 | + */ | |
270 | + | |
271 | + import std.algorithm.searching : countUntil; | |
272 | + import std.file : getcwd, remove; | |
273 | + import std.stdio : File, writeln; | |
274 | + import std.string : split, strip; | |
275 | + | |
276 | + import add : handle_add; | |
277 | + import create : handle_create; | |
278 | + import del : handle_delete; | |
279 | + import update : handle_update; | |
280 | + import util : NUMBER_OF_ML_HEADERS; | |
281 | + | |
282 | + string[] addArgs = ["ml_testing", "item01"]; | |
283 | + string[] updateArgs = ["ml_testing", "1", "-s", "COMPLETE"]; | |
284 | + string[] deleteArgs = ["ml_testing", "1"]; | |
285 | + | |
286 | + handle_create("medialist-cli-unittest", "ml_testing", getcwd()); | |
287 | + handle_add ("medialist-cli-unittest", addArgs, getcwd()); | |
288 | + | |
289 | + File ml_testing = File("ml_testing.tsv"); | |
290 | + scope(exit) remove("ml_testing.tsv"); | |
291 | + | |
292 | + string firstLine = ml_testing.readln.strip; | |
293 | + assert (NUMBER_OF_ML_HEADERS == firstLine.split("\t").length, "Different number of headers"); | |
294 | + | |
295 | + ptrdiff_t lastUpdatedIndex = firstLine.split("\t").countUntil("last_updated"); | |
296 | + assert (-1 != lastUpdatedIndex, "Couldn't find 'last_updated' header"); | |
297 | + | |
298 | + string secondLine = ml_testing.readln.strip; | |
299 | + assert ("" != secondLine.split("\t")[lastUpdatedIndex], "'last_updated' is initially empty"); | |
300 | + | |
301 | + ml_testing.close(); | |
302 | + | |
303 | + handle_update ("medialist-cli-unittest", updateArgs, getcwd()); | |
304 | + | |
305 | + ml_testing.open("ml_testing.tsv"); | |
306 | + | |
307 | + firstLine = ml_testing.readln.strip; | |
308 | + assert (NUMBER_OF_ML_HEADERS == firstLine.split("\t").length, | |
309 | + "Some headers were removed when updating list"); | |
310 | + lastUpdatedIndex = firstLine.split("\t").countUntil("last_updated"); | |
311 | + assert (-1 != lastUpdatedIndex, | |
312 | + "'last_updated' header was removed when updating the list"); | |
313 | + | |
314 | + ml_testing.close(); | |
315 | + | |
316 | + handle_delete ("medialist-cli-unittest", deleteArgs, getcwd()); | |
317 | + | |
318 | + ml_testing.open("ml_testing.tsv"); | |
319 | + | |
320 | + firstLine = ml_testing.readln.strip; | |
321 | + assert (NUMBER_OF_ML_HEADERS == firstLine.split("\t").length, | |
322 | + "Some headers were removed when deleting from list"); | |
323 | + lastUpdatedIndex = firstLine.split("\t").countUntil("last_updated"); | |
324 | + assert (-1 != lastUpdatedIndex, | |
325 | + "'last_updated' header was removed when deleting from the list"); | |
326 | +} | |
327 | + |