mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
055cf342d9
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
35 lines
1.1 KiB
Python
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__)
|