Testable and some tests

Moved the main logic inside a `newpwd` function to make it easier to unit test.
Added a bunch of test cases too, run them with `./run-tests.sh`