Friday, June 24, 2011

DevTnT v2.2 – Notepad++/SpecFlow: Syntax Highlighting for Feature Files

Of course, our favorite text editor Notepad++ gives us syntax highlighting. Although the installation comes with a great set of predefined languages, the gherkin format used for SpecFlow-/Cucumber feature files is not supported out of the box.

Luckily, it is possible to define the bits and pieces for custom languages. In this blog post, Jaco Swarts provides the complete XML file with the language definition for for the gherkin language.

Great!

Due to the mismatch of language features of Notepad++ and language constructs in gherkin, some things are not possible with syntax highlighting:

Tables and Comments

In Jaco’s language definition, tables are considered single line comments as this seems to be the only way to format tables nicely. But table headers cannot be treated differently as done in Visual Studio (see comparison below). As second consequence, real gherkin comments (prefaced by a hash mark – #) are not supported at all. But I think this was a good consideration since tables will be more vital on skimming over a feature file than comments are.

Multiline strings

Gherkin supports multiline strings, delimited by triple quotes. Also this seems not to be possible with the language features of Notepad++.

See the following screenshot for a comparison of the different renderings:

Formatting of English feature file both in Visual Studio and Notepad++

Version for Feature Files in German

Since one major goal of BDD is to raise the bandwidth of the communication channel between all stakeholders of a project including the business/domain experts, it is vital to have feature files in the communication language of the project.

If you are using feature files in German, you want to take advantage of that language definition for Notepad++: http://dl.dropbox.com/u/9238896/gherkin_de.xml. The keywords in this file are taken from the language file of the SpecFlow project.

Issue with gherkin keyword “Funktionalität” (Feature)

Up to now, I did not manage to get Notepad++ to accept the keyword “Funktionalität” correctly. That seems to be the case because of the umlaut a. Although stated as XML entity and displayed properly in the language dialog, it is not rendered as the other keywords:

Formatting of German feature file both in Visual Studio and Notepad++

Note

There seems to be a problem having both the English and the German version installed in parallel. Sometimes the highlighting worked fine, but sometimes event a manual language switch from German to English gherkin (language menu) did not work.

Any hints regarding that are appreciated!

1 comment:

  1. Oh Paul, if you think that Notepad and Specflow are the only ones that had this issue, then I bet you're never worked with Emacs. I used to work in coop with some french coders through this thing. Trying to do some magic with synthax highlighting in the way you do in this post, the whole application's settings became corrupted suddenly - it let me to open some files occasionally and went down right after a few seconds. Fortunately, I found the right tool in the first hour of my googling. It is just a simple app, that repairs all file associations really fast and help me to open and work with every file formats as well as to open .txt file https://wikiext.com/txt So, I really suggest you to keep this one closer to yourself, or - moreover - switch to another up-to-dated text editor

    ReplyDelete