|
2 | 2 |
|
3 | 3 | import unittest
|
4 | 4 | import os
|
| 5 | +import string |
5 | 6 | import warnings
|
6 | 7 |
|
7 | 8 | from fnmatch import fnmatch, fnmatchcase, translate, filter
|
@@ -91,6 +92,76 @@ def test_sep(self):
|
91 | 92 | check('usr/bin', 'usr\\bin', normsep)
|
92 | 93 | check('usr\\bin', 'usr\\bin')
|
93 | 94 |
|
| 95 | + def test_char_set(self): |
| 96 | + ignorecase = os.path.normcase('ABC') == os.path.normcase('abc') |
| 97 | + check = self.check_match |
| 98 | + tescases = string.ascii_lowercase + string.digits + string.punctuation |
| 99 | + for c in tescases: |
| 100 | + check(c, '[az]', c in 'az') |
| 101 | + check(c, '[!az]', c not in 'az') |
| 102 | + # Case insensitive. |
| 103 | + for c in tescases: |
| 104 | + check(c, '[AZ]', (c in 'az') and ignorecase) |
| 105 | + check(c, '[!AZ]', (c not in 'az') or not ignorecase) |
| 106 | + for c in string.ascii_uppercase: |
| 107 | + check(c, '[az]', (c in 'AZ') and ignorecase) |
| 108 | + check(c, '[!az]', (c not in 'AZ') or not ignorecase) |
| 109 | + # Repeated same character. |
| 110 | + for c in tescases: |
| 111 | + check(c, '[aa]', c == 'a') |
| 112 | + # Special cases. |
| 113 | + for c in tescases: |
| 114 | + check(c, '[^az]', c in '^az') |
| 115 | + check(c, '[[az]', c in '[az') |
| 116 | + check(c, r'[\]', c == '\\') |
| 117 | + check(c, r'[\az]', c in r'\az') |
| 118 | + check(c, r'[!]]', c != ']') |
| 119 | + check('[', '[') |
| 120 | + check('[]', '[]') |
| 121 | + check('[!', '[!') |
| 122 | + check('[!]', '[!]') |
| 123 | + |
| 124 | + def test_range(self): |
| 125 | + ignorecase = os.path.normcase('ABC') == os.path.normcase('abc') |
| 126 | + check = self.check_match |
| 127 | + tescases = string.ascii_lowercase + string.digits + string.punctuation |
| 128 | + for c in tescases: |
| 129 | + check(c, '[b-d]', c in 'bcd') |
| 130 | + check(c, '[!b-d]', c not in 'bcd') |
| 131 | + check(c, '[b-dx-z]', c in 'bcdxyz') |
| 132 | + check(c, '[!b-dx-z]', c not in 'bcdxyz') |
| 133 | + # Case insensitive. |
| 134 | + for c in tescases: |
| 135 | + check(c, '[B-D]', (c in 'bcd') and ignorecase) |
| 136 | + check(c, '[!B-D]', (c not in 'bcd') or not ignorecase) |
| 137 | + for c in string.ascii_uppercase: |
| 138 | + check(c, '[b-d]', (c in 'BCD') and ignorecase) |
| 139 | + check(c, '[!b-d]', (c not in 'BCD') or not ignorecase) |
| 140 | + # Upper bound == lower bound. |
| 141 | + for c in tescases: |
| 142 | + check(c, '[b-b]', c == 'b') |
| 143 | + # Special cases. |
| 144 | + for c in tescases: |
| 145 | + check(c, '[!-#]', c not in '-#') |
| 146 | + check(c, '[!--/]', c not in '-./') |
| 147 | + check(c, '[^-`]', c in '^_`') |
| 148 | + check(c, '[[-^]', c in r'[\]^') |
| 149 | + check(c, r'[\-^]', c in r'\]^') |
| 150 | + check(c, '[b-]', c in '-b') |
| 151 | + check(c, '[!b-]', c not in '-b') |
| 152 | + check(c, '[-b]', c in '-b') |
| 153 | + check(c, '[!-b]', c not in '-b') |
| 154 | + check(c, '[-]', c in '-') |
| 155 | + check(c, '[!-]', c not in '-') |
| 156 | + # Upper bound is less that lower bound: error in RE. |
| 157 | + for c in tescases: |
| 158 | + check(c, '[d-b]', False) |
| 159 | + check(c, '[!d-b]', True) |
| 160 | + check(c, '[d-bx-z]', c in 'xyz') |
| 161 | + check(c, '[!d-bx-z]', c not in 'xyz') |
| 162 | + check(c, '[d-b^-`]', c in '^_`') |
| 163 | + check(c, '[d-b[-^]', c in '[\\]^') |
| 164 | + |
94 | 165 | def test_warnings(self):
|
95 | 166 | with warnings.catch_warnings():
|
96 | 167 | warnings.simplefilter('error', Warning)
|
|
0 commit comments