Tests and code for square brackets