2122: fixed crash caused by indexing with the wrong variable

Added a bunch of unittests, I think we cover all the cases of diffing
now.  Added a couple comments to the diffing code.
Merge pull request #4 from pculture/x-2122

2122: fixed crash caused by indexing with the wrong variable