Added test suite, makefile and a few bugfixes

Hi,

I just added a test suite with some of the most common (I think) use-cases or breaks for the lib. In the mean-time, I had to add a simple Makefile to build and test, and I also fixed a couple of bugs I encountered while testing for some behaviors, mainly minor.

Testing is cli-only, for now, as I wanted to keep the branch simple. It uses Mocha and Chai. Browser testing support may come later, if desired, along with a `package.json`.

I tried to keep coherent with your coding style, so let me know what you think, and feel free to cherry-pick.