Fix inverted condition and add tests.

There are a couple more places with the same problem.  I've added tests for them.