|
20 | 20 |
|
21 | 21 | import pytest
|
22 | 22 |
|
| 23 | +from playwright._impl._glob import glob_to_regex |
23 | 24 | from playwright.async_api import (
|
24 | 25 | Browser,
|
25 | 26 | BrowserContext,
|
@@ -1041,3 +1042,47 @@ async def handle_request(route: Route) -> None:
|
1041 | 1042 | assert response
|
1042 | 1043 | assert response.status == 200
|
1043 | 1044 | assert await response.json() == {"foo": "bar"}
|
| 1045 | + |
| 1046 | + |
| 1047 | +async def test_glob_to_regex() -> None: |
| 1048 | + assert glob_to_regex("**/*.js").match("https://localhost:8080/foo.js") |
| 1049 | + assert not glob_to_regex("**/*.css").match("https://localhost:8080/foo.js") |
| 1050 | + assert not glob_to_regex("*.js").match("https://localhost:8080/foo.js") |
| 1051 | + assert glob_to_regex("https://**/*.js").match("https://localhost:8080/foo.js") |
| 1052 | + assert glob_to_regex("http://localhost:8080/simple/path.js").match( |
| 1053 | + "http://localhost:8080/simple/path.js" |
| 1054 | + ) |
| 1055 | + assert glob_to_regex("http://localhost:8080/?imple/path.js").match( |
| 1056 | + "http://localhost:8080/Simple/path.js" |
| 1057 | + ) |
| 1058 | + assert glob_to_regex("**/{a,b}.js").match("https://localhost:8080/a.js") |
| 1059 | + assert glob_to_regex("**/{a,b}.js").match("https://localhost:8080/b.js") |
| 1060 | + assert not glob_to_regex("**/{a,b}.js").match("https://localhost:8080/c.js") |
| 1061 | + |
| 1062 | + assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.jpg") |
| 1063 | + assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.jpeg") |
| 1064 | + assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.png") |
| 1065 | + assert not glob_to_regex("**/*.{png,jpg,jpeg}").match( |
| 1066 | + "https://localhost:8080/c.css" |
| 1067 | + ) |
| 1068 | + assert glob_to_regex("foo*").match("foo.js") |
| 1069 | + assert not glob_to_regex("foo*").match("foo/bar.js") |
| 1070 | + assert not glob_to_regex("http://localhost:3000/signin-oidc*").match( |
| 1071 | + "http://localhost:3000/signin-oidc/foo" |
| 1072 | + ) |
| 1073 | + assert glob_to_regex("http://localhost:3000/signin-oidc*").match( |
| 1074 | + "http://localhost:3000/signin-oidcnice" |
| 1075 | + ) |
| 1076 | + |
| 1077 | + assert glob_to_regex("**/three-columns/settings.html?**id=[a-z]**").match( |
| 1078 | + "http://mydomain:8080/blah/blah/three-columns/settings.html?id=settings-e3c58efe-02e9-44b0-97ac-dd138100cf7c&blah" |
| 1079 | + ) |
| 1080 | + |
| 1081 | + assert glob_to_regex("\\?") == re.compile(r"^\?$") |
| 1082 | + assert glob_to_regex("\\") == re.compile(r"^\\$") |
| 1083 | + assert glob_to_regex("\\\\") == re.compile(r"^\\$") |
| 1084 | + assert glob_to_regex("\\[") == re.compile(r"^\[$") |
| 1085 | + assert glob_to_regex("[a-z]") == re.compile(r"^[a-z]$") |
| 1086 | + assert glob_to_regex("$^+.\\*()|\\?\\{\\}\\[\\]") == re.compile( |
| 1087 | + r"^\$\^\+\.\*\(\)\|\?\{\}\[\]$" |
| 1088 | + ) |
0 commit comments