This gist has very good test cases. Mind to reuse they? https://gist.github.com/iwiznia/6295952