# coding: utf-8
from __future__ import unicode_literals

from ...matcher import Matcher

import pytest


@pytest.mark.models('en')
def test_issue429(EN):
    def merge_phrases(matcher, doc, i, matches):
      if i != len(matches) - 1:
        return None
      spans = [(ent_id, ent_id, doc[start:end]) for ent_id, start, end in matches]
      for ent_id, label, span in spans:
        span.merge('NNP' if label else span.root.tag_, span.text, EN.vocab.strings[label])

    doc = EN('a')
    matcher = Matcher(EN.vocab)
    matcher.add('TEST', merge_phrases, [{'ORTH': 'a'}])
    doc = EN.make_doc('a b c')
    EN.tensorizer(doc)
    EN.tagger(doc)
    matcher(doc)
    EN.entity(doc)

@@ -202,16 +202,18 @@
 :%0A      
+  
 if i != 
@@ -238,16 +238,20 @@
         
+    
 return N
@@ -256,24 +256,26 @@
  None%0A      
+ 
+ 
 spans = %5B(en
@@ -345,16 +345,18 @@
 %5D%0A      
+  
 for ent_
@@ -385,24 +385,28 @@
 ns:%0A        
+   
+ 
 span.merge('
@@ -404,16 +404,38 @@
 n.merge(
+%0A                tag=(
 'NNP' if
@@ -464,44 +464,74 @@
 tag_
-, span.text, EN.vocab.strings%5Blabel%5D
+),%0A                lemma=span.text,%0A                label='PERSON'
 )%0A%0A 

Update regression test