code: def test_query_highlight():
      qp = QueryParser("a", None)
      hf = highlight.HtmlFormatter()
  
      def do(text, terms):
          q = qp.parse(text)
          tks = [tk for tk in q.all_tokens() if tk.text in terms]
          for tk in tks:
              if tk.startchar is None or tk.endchar is None:
                  assert False, tk
          fragment = highlight.Fragment(text, tks)
          return hf.format_fragment(fragment)
  
      assert (
          do("a b c d", ["b"])
          == 'a <strong class="match term0">b</strong> c d'
      )
      assert (
          do('a (x:b OR y:"c d") e', ("b", "c"))
          == 'a (x:<strong class="match term0">b</strong> OR y:"<strong class="match term1">c</strong> d") e'
      )
  
imports: from __future__ import with_statement
  import gzip
  from whoosh import analysis, fields, highlight, query, spelling
  from whoosh.compat import u
  from whoosh.qparser import QueryParser
  from whoosh.support.levenshtein import levenshtein
  from whoosh.util.testing import TempIndex
label_desc: Use image node_id 6 for calling a global function with example usage: test_query_highlight() and returns: hf