mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add testcase for compile_matchers()
This commit is contained in:
parent
db23797c57
commit
829b5631a3
83
tests/test_util_matching.py
Normal file
83
tests/test_util_matching.py
Normal file
@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_util_matching
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests sphinx.util.matching functions.
|
||||
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from sphinx.util.matching import compile_matchers
|
||||
|
||||
|
||||
def test_compile_matchers():
|
||||
# exact matching
|
||||
pat = compile_matchers(['hello.py']).pop()
|
||||
assert pat('hello.py')
|
||||
assert not pat('hello-py')
|
||||
assert not pat('subdir/hello.py')
|
||||
|
||||
# wild card (*)
|
||||
pat = compile_matchers(['hello.*']).pop()
|
||||
assert pat('hello.py')
|
||||
assert pat('hello.rst')
|
||||
|
||||
pat = compile_matchers(['*.py']).pop()
|
||||
assert pat('hello.py')
|
||||
assert pat('world.py')
|
||||
assert not pat('subdir/hello.py')
|
||||
|
||||
# wild card (**)
|
||||
pat = compile_matchers(['hello.**']).pop()
|
||||
assert pat('hello.py')
|
||||
assert pat('hello.rst')
|
||||
assert pat('hello.py/world.py')
|
||||
|
||||
pat = compile_matchers(['**.py']).pop()
|
||||
assert pat('hello.py')
|
||||
assert pat('world.py')
|
||||
assert pat('subdir/hello.py')
|
||||
|
||||
pat = compile_matchers(['**/hello.py']).pop()
|
||||
assert not pat('hello.py')
|
||||
assert pat('subdir/hello.py')
|
||||
assert pat('subdir/subdir/hello.py')
|
||||
|
||||
# wild card (?)
|
||||
pat = compile_matchers(['hello.?']).pop()
|
||||
assert pat('hello.c')
|
||||
assert not pat('hello.py')
|
||||
|
||||
# pattern ([...])
|
||||
pat = compile_matchers(['hello[12\\].py']).pop()
|
||||
assert pat('hello1.py')
|
||||
assert pat('hello2.py')
|
||||
assert pat('hello\\.py')
|
||||
assert not pat('hello3.py')
|
||||
|
||||
pat = compile_matchers(['hello[^12].py']).pop() # "^" is not negative identifier
|
||||
assert pat('hello1.py')
|
||||
assert pat('hello2.py')
|
||||
assert pat('hello^.py')
|
||||
assert not pat('hello3.py')
|
||||
|
||||
# negative pattern ([!...])
|
||||
pat = compile_matchers(['hello[!12].py']).pop()
|
||||
assert not pat('hello1.py')
|
||||
assert not pat('hello2.py')
|
||||
assert not pat('hello/.py') # negative pattern does not match to "/"
|
||||
assert pat('hello3.py')
|
||||
|
||||
# non patterns
|
||||
pat = compile_matchers(['hello[.py']).pop()
|
||||
assert pat('hello[.py')
|
||||
assert not pat('hello.py')
|
||||
|
||||
pat = compile_matchers(['hello[].py']).pop()
|
||||
assert pat('hello[].py')
|
||||
assert not pat('hello.py')
|
||||
|
||||
pat = compile_matchers(['hello[!].py']).pop()
|
||||
assert pat('hello[!].py')
|
||||
assert not pat('hello.py')
|
Loading…
Reference in New Issue
Block a user