Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixes and refactorings to utils_strv_shorten_file_list() and friends #2262
When merging #1445 we found that the results could be improved.
I promised to fix the deficient results along with proper unit tests so here we go.
Basically utils_strv_shorten_file_list() can repaired and simplified at the same time by a relatively minor change to the supprting utils_strv_find_lcs(). This is all backed up by new unit tests which tests the related functions plus (now reborn) utils_strv_new().
We didn't use unit tests so far so I have picked up the glib testing framework. While there are better frameworks out there glib's it gets the job done and doesn't impose extra dependencies. For upcoming fixes and refactorings to utils_strv_find_lcs and utils_strv_shorten_file_list I would like to make sure to not introduce regressions and unit tests are ideal for that. A function to be tested must be exported by libgeany.so. Use GEANY_EXPORT_SYMBOL for that. It's not the same as GEANY_API_SYMBOL to avoid the impression that it's OK to use them in plugins. Also no doxygen comments for those. I resurrected utils_strv_new() because it's convinient to have in the tests. The function has its own test suite since it's otherwise unused.
…_list() Because utils_strv_find_lcs() didn't consisider path component boundaries it have have found substrings that are longest in itself but not so ideal when utils_strv_shorten_file_list() applied path boundaries. utils_strv_find_lcs() now can optionally restrict the substring between delimiters (i.e. dir separators). In that mode it will find the longest substring that is also sorrounded by the delimiters (there may be more delimiters inside the string). The unit test that demonstrated the deficient is fixed since now the expected substitution takes place.
Since utils_strv_find_lcs() respects path components by itself, utils_strv_shorten_file_list() can be massively simplified. The path list does not be prepared and post-processed around utils_strv_find_lcs() anymore because it does the right thing already. This saves a lot of complexity and also duplicating the string vector once.