Debian Codegraph @

tests/test-minifileset.py

raw
1 from mercurial import minifileset
2
3
4 def check(text, truecases, falsecases):
5 f = minifileset.compile(text)
6 for args in truecases:
7 if not f(*args):
8 print('unexpected: %r should include %r' % (text, args))
9 for args in falsecases:
10 if f(*args):
11 print('unexpected: %r should exclude %r' % (text, args))
12
13
14 check(b'all()', [(b'a.php', 123), (b'b.txt', 0)], [])
15 check(b'none()', [], [(b'a.php', 123), (b'b.txt', 0)])
16 check(b'!!!!((!(!!all())))', [], [(b'a.php', 123), (b'b.txt', 0)])
17
18 check(
19 b'"path:a" & (**.b | **.c)', [(b'a/b.b', 0), (b'a/c.c', 0)], [(b'b/c.c', 0)]
20 )
21 check(
22 b'(path:a & **.b) | **.c', [(b'a/b.b', 0), (b'a/c.c', 0), (b'b/c.c', 0)], []
23 )
24
25 check(
26 b'**.bin - size("<20B")', [(b'b.bin', 21)], [(b'a.bin', 11), (b'b.txt', 21)]
27 )
28
29 check(
30 b'!!**.bin or size(">20B") + "path:bin" or !size(">10")',
31 [(b'a.bin', 11), (b'b.txt', 21), (b'bin/abc', 11)],
32 [(b'a.notbin', 11), (b'b.txt', 11), (b'bin2/abc', 11)],
33 )
34
35 check(
36 b'(**.php and size(">10KB")) | **.zip | ("path:bin" & !"path:bin/README") '
37 b' | size(">1M")',
38 [(b'a.php', 15000), (b'a.zip', 0), (b'bin/a', 0), (b'bin/README', 1e7)],
39 [(b'a.php', 5000), (b'b.zip2', 0), (b't/bin/a', 0), (b'bin/README', 1)],
40 )