From 86cd7f0efdabadb172894c39183f9645dbd632aa Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Tue, 20 Aug 2019 16:33:09 +0200 Subject: [PATCH] Add regression test for #4120 --- spacy/tests/regression/test_issue4120.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spacy/tests/regression/test_issue4120.py diff --git a/spacy/tests/regression/test_issue4120.py b/spacy/tests/regression/test_issue4120.py new file mode 100644 index 000000000..652825064 --- /dev/null +++ b/spacy/tests/regression/test_issue4120.py @@ -0,0 +1,27 @@ +# coding: utf8 +from __future__ import unicode_literals + +import pytest +from spacy.matcher import Matcher +from spacy.tokens import Doc + + +@pytest.mark.xfail +def test_issue4120(en_vocab): + """Test that matches without a final {OP: ?} token are returned.""" + matcher = Matcher(en_vocab) + matcher.add("TEST", None, [{"ORTH": "a"}, {"OP": "?"}]) + doc1 = Doc(en_vocab, words=["a"]) + assert len(matcher(doc1)) == 1 # works + doc2 = Doc(en_vocab, words=["a", "b", "c"]) + assert len(matcher(doc2)) == 2 # doesn't work + + matcher = Matcher(en_vocab) + matcher.add("TEST", None, [{"ORTH": "a"}, {"OP": "?"}, {"ORTH": "b"}]) + doc3 = Doc(en_vocab, words=["a", "b", "b", "c"]) + assert len(matcher(doc3)) == 2 # works + + matcher = Matcher(en_vocab) + matcher.add("TEST", None, [{"ORTH": "a"}, {"OP": "?"}, {"ORTH": "b", "OP": "?"}]) + doc4 = Doc(en_vocab, words=["a", "b", "b", "c"]) + assert len(matcher(doc4)) == 3 # doesn't work