code: def test_matcher_as_spans(matcher):
      """Test the new as_spans=True API."""
      text = "JavaScript is good but Java is better"
      doc = Doc(matcher.vocab, words=text.split())
      matches = matcher(doc, as_spans=True)
      assert len(matches) == 2
      assert isinstance(matches[0], Span)
      assert matches[0].text == "JavaScript"
      assert matches[0].label_ == "JS"
      assert isinstance(matches[1], Span)
      assert matches[1].text == "Java"
      assert matches[1].label_ == "Java"
  
      matches = matcher(doc[1:], as_spans=True)
      assert len(matches) == 1
      assert isinstance(matches[0], Span)
      assert matches[0].text == "Java"
      assert matches[0].label_ == "Java"
  
imports: import pytest
  from mock import Mock
  from spacy.matcher import Matcher
  from spacy.tokens import Doc, Span, Token
  from ..doc.test_underscore import clean_underscore
label_desc: Use image node_id 46 for calling a global function with example usage: test_matcher_as_spans(matcher) without return types