Factor out common path in moves and add QUnit tests

The unit tests in `tests/util_test.js` make it pretty clear what the behavior is.

Using difflib may be overkill, but it works and we already have it available!

Fixes #32