Fix cd magic for ~ paths and add test
Add cd magic test