Simon Context filter

The Context filter in Simon is a sophisticated filter that takes the previous filter’s input and match range to output some context around that filter’s output text.

It includes controls to specify the maximum number of characters before and/or after the matched range, and/or a delimiter before and/or after the matched range. So for example you can show up to 50 characters, stopping at a line break.

This filter is unusual in that it requires a previous filter to be used, and that needs to be either a Block– or Find-based filter, as those are the only ones that output the needed match range information.

The Context filter uses the Input specified in the test to determine which filter’s input and match variables to use: if you have two previous filters, you can make the Context filter look at the first one by choosing Filter1OutputText instead of the default FilterOutputText (which means the proceeding filter).

The match range is available in variables used by the Context filter, and can be used in your custom filters or notifiers if you wish:

{FilterMatchLocation}: the position of the match in the input text, e.g. the text between the Blocks, or the Find result. Note that the location is zero-based.

{FilterMatchLength}: The length of that match.

{FilterMatchEnd}: The location plus the length, for convenience.

You don’t need to worry about these variables for the Context filter, though; it uses them internally.

Here’s a simple example of this filter in action.

This is from a Web test that looks at the Daring Fireball site. It has a Find Required filter to look for the word “finally”, then if that succeeds a Context filter to output the enclosing paragraph. To round it out, if the Find filter fails, the Override as Unchanged failure case is used, to avoid the test resulting in a failure if Gruber hasn’t used the word “finally” recently.

Below the filters, you can see the Preview pane’s output, which you’ll notice includes the word “finally” towards the end.

I hope this will be a useful filter for many of your tests. Simon is a powerful tool, with lots of other handy filters, services, and notifiers.