Makes lexer case insensitive

The lexer is now case insensitive; it converts all tags to lower case as it processes them.
Includes tests to check the behaviour and some test code cleanup.