Added additional validation. Moved tests to own file.

This is currently broken with the latest Rust nightly. I haven't
had time to fix the breakage.