Added tests for gh-2592, inlcuding edge case.

Work done with @certik.