Add sophisticated trimLabels() test cases.

Probably will need to make the trimLabels() method neater and easier to understand, as this functionality is probably not going to change.