Tests and fix for #1689