sapling/eden/scm/tests/test-match.py
Jun Wu 055cf342d9 pathmatcher: hint globset to use prefix strategy instead of regexp strategy
Summary:
`globset` supports multiple matching strategies, including literal prefix
(backed by AhoCorasick), or regexp, etc.

In theory patterns like `foo/**` (where `*` cannot match `/`) can use `foo`
prefix strategy. However, the implementation detail of `globset` wouldn't
accept it as a prefix. But `foo/*` (where `*` can match `/`) can be treated as
a prefix. Transform the former pattern to the latter to hint `globset` to use
the optimal strategies.

Reviewed By: sfilipco

Differential Revision: D18500298

fbshipit-source-id: 39e604d6157a919b75c392488b6d42375e518c16
2019-11-14 14:27:39 -08:00

35 lines
1.1 KiB
Python

from __future__ import absolute_import
import unittest
import silenttestrunner
from edenscm.mercurial import match as matchmod
class NeverMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.nevermatcher("", "")
self.assertFalse(m.visitdir(""))
self.assertFalse(m.visitdir("dir"))
def testManyGlobRaises(self):
n = 10000
rules = ["a/b/*/c/d/e/f/g/%s/**" % i for i in range(n)]
with self.assertRaises(ValueError):
# "Compiled regex exceeds size limit of 10485760 bytes."
matchmod.treematcher("", "", rules=rules)
def testManyPrefixes(self):
n = 10000
rules = ["a/b/c/d/e/f/g/%s/**" % i for i in range(n)]
m = matchmod.treematcher("", "", rules=rules)
self.assertTrue(m.visitdir("a"))
self.assertTrue(m.visitdir("a/b"))
self.assertEqual(m.visitdir("a/b/c/d/e/f/g/1"), "all")
self.assertFalse(m.visitdir("b"))
self.assertTrue(m("a/b/c/d/e/f/g/99/x"))
if __name__ == "__main__":
silenttestrunner.main(__name__)