|
| 1 | +from aws_xray_sdk.core.utils.search_pattern import wildcard_match |
| 2 | + |
| 3 | + |
| 4 | +def test_match_exact_positive(): |
| 5 | + pat = 'foo' |
| 6 | + bar = 'foo' |
| 7 | + assert wildcard_match(pat, bar) |
| 8 | + |
| 9 | + |
| 10 | +def test_match_exact_negative(): |
| 11 | + pat = 'foo' |
| 12 | + bar = 'cat' |
| 13 | + assert not wildcard_match(pat, bar) |
| 14 | + |
| 15 | + |
| 16 | +def test_single_wildcard_positive(): |
| 17 | + pat = 'fo?' |
| 18 | + bar = 'foo' |
| 19 | + assert wildcard_match(pat, bar) |
| 20 | + |
| 21 | + |
| 22 | +def test_single_wildcard_negative(): |
| 23 | + pat = 'f?o' |
| 24 | + bar = 'boo' |
| 25 | + assert not wildcard_match(pat, bar) |
| 26 | + |
| 27 | + |
| 28 | +def test_multiple_wildcard_positive(): |
| 29 | + pat = '?o?' |
| 30 | + bar = 'foo' |
| 31 | + assert wildcard_match(pat, bar) |
| 32 | + |
| 33 | + |
| 34 | +def test_multiple_wildcard_negative(): |
| 35 | + pat = 'f??' |
| 36 | + bar = 'boo' |
| 37 | + assert not wildcard_match(pat, bar) |
| 38 | + |
| 39 | + |
| 40 | +def test_glob_positive_zero_or_more(): |
| 41 | + pat = 'foo*' |
| 42 | + bar = 'foo' |
| 43 | + assert wildcard_match(pat, bar) |
| 44 | + |
| 45 | + |
| 46 | +def test_glob_negative_zero_or_more(): |
| 47 | + pat = 'foo*' |
| 48 | + bar = 'fo0' |
| 49 | + assert not wildcard_match(pat, bar) |
| 50 | + |
| 51 | + |
| 52 | +def test_glob_negative(): |
| 53 | + pat = 'fo*' |
| 54 | + bar = 'boo' |
| 55 | + assert not wildcard_match(pat, bar) |
| 56 | + |
| 57 | + |
| 58 | +def test_glob_and_single_positive(): |
| 59 | + pat = '*o?' |
| 60 | + bar = 'foo' |
| 61 | + assert wildcard_match(pat, bar) |
| 62 | + |
| 63 | + |
| 64 | +def test_glob_and_single_negative(): |
| 65 | + pat = 'f?*' |
| 66 | + bar = 'boo' |
| 67 | + assert not wildcard_match(pat, bar) |
| 68 | + |
| 69 | + |
| 70 | +def test_pure_wildcard(): |
| 71 | + pat = '*' |
| 72 | + bar = 'foo' |
| 73 | + assert wildcard_match(pat, bar) |
| 74 | + |
| 75 | + |
| 76 | +def test_exact_match(): |
| 77 | + pat = '6573459' |
| 78 | + bar = '6573459' |
| 79 | + assert wildcard_match(pat, bar) |
| 80 | + |
| 81 | + |
| 82 | +def test_misc(): |
| 83 | + animal1 = '?at' |
| 84 | + animal2 = '?o?se' |
| 85 | + animal3 = '*s' |
| 86 | + |
| 87 | + vehicle1 = 'J*' |
| 88 | + vehicle2 = '????' |
| 89 | + |
| 90 | + assert wildcard_match(animal1, 'bat') |
| 91 | + assert wildcard_match(animal1, 'cat') |
| 92 | + assert wildcard_match(animal2, 'horse') |
| 93 | + assert wildcard_match(animal2, 'mouse') |
| 94 | + assert wildcard_match(animal3, 'dogs') |
| 95 | + assert wildcard_match(animal3, 'horses') |
| 96 | + |
| 97 | + assert wildcard_match(vehicle1, 'Jeep') |
| 98 | + assert wildcard_match(vehicle2, 'ford') |
| 99 | + assert not wildcard_match(vehicle2, 'chevy') |
| 100 | + assert wildcard_match('*', 'cAr') |
| 101 | + |
| 102 | + assert wildcard_match('*/foo', '/bar/foo') |
| 103 | + |
| 104 | + |
| 105 | +def test_case_insensitivity(): |
| 106 | + assert wildcard_match('Foo', 'Foo', False) |
| 107 | + assert wildcard_match('Foo', 'Foo', True) |
| 108 | + |
| 109 | + assert not wildcard_match('Foo', 'FOO', False) |
| 110 | + assert wildcard_match('Foo', 'FOO', True) |
| 111 | + |
| 112 | + assert wildcard_match('Fo*', 'Foo0', False) |
| 113 | + assert wildcard_match('Fo*', 'Foo0', True) |
| 114 | + |
| 115 | + assert not wildcard_match('Fo*', 'FOo0', False) |
| 116 | + assert wildcard_match('Fo*', 'FOo0', True) |
| 117 | + |
| 118 | + assert wildcard_match('Fo?', 'Foo', False) |
| 119 | + assert wildcard_match('Fo?', 'Foo', True) |
| 120 | + |
| 121 | + assert not wildcard_match('Fo?', 'FOo', False) |
| 122 | + assert wildcard_match('Fo?', 'FoO', False) |
| 123 | + assert wildcard_match('Fo?', 'FOO', True) |
| 124 | + |
| 125 | + |
| 126 | +def test_no_globs(): |
| 127 | + assert not wildcard_match('abcd', 'abc') |
| 128 | + |
| 129 | + |
| 130 | +def test_edge_case_globs(): |
| 131 | + assert wildcard_match('', '') |
| 132 | + assert wildcard_match('a', 'a') |
| 133 | + assert wildcard_match('*a', 'a') |
| 134 | + assert wildcard_match('*a', 'ba') |
| 135 | + assert wildcard_match('a*', 'a') |
| 136 | + assert wildcard_match('a*', 'ab') |
| 137 | + assert wildcard_match('a*a', 'aa') |
| 138 | + assert wildcard_match('a*a', 'aba') |
| 139 | + assert wildcard_match('a*a', 'aaa') |
| 140 | + assert wildcard_match('a*a*', 'aa') |
| 141 | + assert wildcard_match('a*a*', 'aba') |
| 142 | + assert wildcard_match('a*a*', 'aaa') |
| 143 | + assert wildcard_match('a*a*', 'aaaaaaaaaaaaaaaaaaaaaaaaaa') |
| 144 | + assert wildcard_match('a*b*a*b*a*b*a*b*a*', |
| 145 | + 'akljd9gsdfbkjhaabajkhbbyiaahkjbjhbuykjakjhabkjhbabjhkaabbabbaaakljdfsjklababkjbsdabab') |
| 146 | + assert not wildcard_match('a*na*ha', 'anananahahanahana') |
| 147 | + |
| 148 | + |
| 149 | +def test_multi_globs(): |
| 150 | + assert wildcard_match('*a', 'a') |
| 151 | + assert wildcard_match('**a', 'a') |
| 152 | + assert wildcard_match('***a', 'a') |
| 153 | + assert wildcard_match('**a*', 'a') |
| 154 | + assert wildcard_match('**a**', 'a') |
| 155 | + |
| 156 | + assert wildcard_match('a**b', 'ab') |
| 157 | + assert wildcard_match('a**b', 'abb') |
| 158 | + |
| 159 | + assert wildcard_match('*?', 'a') |
| 160 | + assert wildcard_match('*?', 'aa') |
| 161 | + assert wildcard_match('*??', 'aa') |
| 162 | + assert not wildcard_match('*???', 'aa') |
| 163 | + assert wildcard_match('*?', 'aaa') |
| 164 | + |
| 165 | + assert wildcard_match('?', 'a') |
| 166 | + assert not wildcard_match('??', 'a') |
| 167 | + |
| 168 | + assert wildcard_match('?*', 'a') |
| 169 | + assert wildcard_match('*?', 'a') |
| 170 | + assert not wildcard_match('?*?', 'a') |
| 171 | + assert wildcard_match('?*?', 'aa') |
| 172 | + assert wildcard_match('*?*', 'a') |
| 173 | + |
| 174 | + assert not wildcard_match('*?*a', 'a') |
| 175 | + assert wildcard_match('*?*a*', 'ba') |
0 commit comments