function findSingle(str, pos, ch) {
    for (;;) {
      var found = str.indexOf(ch, pos);
      if (found == -1) return null;
      if (str.charAt(found + 1) != ch) return found;
      pos = found + 2;
    }
  }
Helper to test CodeMirror highlighting modes. It pretty prints output of the
highlighter and can check against expected styles.

Mode tests are registered by calling test.mode(testName, mode,
tokens), where mode is a mode object as returned by
CodeMirror.getMode, and tokens is an array of lines that make up
the test.

These lines are strings, in which styled stretches of code are
enclosed in brackets `[]`, and prefixed by their style. For
example, `[keyword if]`. Brackets in the code itself must be
duplicated to prevent them from being interpreted as token
boundaries. For example `a[[i]]` for `a[i]`. If a token has
multiple styles, the styles must be separated by ampersands, for
example `[tag&error </hmtl>]`.

See the test.js files in the css, markdown, gfm, and stex mode
directories for examples.