Fix double-newline bug in Scala templates

This should fix ticket #1002303. I've also added some basic tests for the ScalaTemplateContext class since it didn't have any before.