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

Adding some unit tests and some small refactorings for practice. I have precious little experience with C, so if I've screwed something up please let me know.