[WIP] Refactor `shorten_*` in path.c

Adding some unit tests and some small refactorings for practice. I have precious little experience with C, so if you see something that is completely screwed up please let me know.