Refactoring the encoder + more tests.

The basic structure of the encoder has been preserved, but it has been
significantly gutted to reduce code duplication. Also, since the
encoding process can produce an error at almost any step, error handling
is now done using panic/defer internally (but still exposed as `error`
values in the API).

Some redundant case analysis has been removed, which has somewhat
simplified type handling. I think there is more case analysis that
can be removed.

Writing indentation now has a single point of truth.

Writing "key = value" has now been coupled.

I've also included more tests that exercise some other bugs I found
while refactoring. I also added a test for nested table arrays.