Add text-file doctests and fix a found bug.

A bug found by adding unittests. Fancy that.