Skip to content

Commit 90dfee0

Browse files
refactor: subvert/TestScope/RootDir/
1 parent 54388d0 commit 90dfee0

1 file changed

Lines changed: 69 additions & 71 deletions

File tree

moz-webgpu-cts/src/wpt/path.rs

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,36 @@ pub(crate) enum Browser {
1818
}
1919

2020
impl Browser {
21-
/// NOTE: Keep this implementation in sync with [`TestScope::url_prefix`].
22-
pub(crate) fn strip_scope_url_prefix<'a>(
23-
&self,
24-
url_path: &'a str,
25-
) -> Option<(TestScope, &'a str)> {
26-
let strip_prefix = |prefix, scope| {
21+
/// NOTE: Keep this implementation in sync with [`RootDir::url_prefix`].
22+
pub(crate) fn strip_wpt_url_prefix<'a>(&self, url_path: &'a str) -> Option<(RootDir, &'a str)> {
23+
let strip_prefix = |prefix, root_dir| {
2724
url_path
2825
.strip_prefix(prefix)
29-
.map(|stripped| (scope, stripped))
26+
.map(|stripped| (root_dir, stripped))
3027
};
3128
match self {
32-
Browser::Firefox => strip_prefix("/_mozilla/", FirefoxTestScope::Mozilla.into())
33-
.or_else(|| strip_prefix("/", FirefoxTestScope::Upstream.into())),
34-
Browser::Servo => strip_prefix("/_webgpu/", ServoTestScope::WebGpu.into()),
29+
Browser::Firefox => strip_prefix("/_mozilla/", FirefoxRootDir::Mozilla.into())
30+
.or_else(|| strip_prefix("/", FirefoxRootDir::Upstream.into())),
31+
Browser::Servo => strip_prefix("/_webgpu/", ServoRootDir::WebGpu.into()),
3532
}
3633
}
3734

38-
/// NOTE: Keep this implementation in sync with [`TestScope::metadata_parent_path_components`].
39-
pub(crate) fn strip_scope_parent_path<'a>(
35+
/// NOTE: Keep this implementation in sync with [`RootDir::components`].
36+
pub(crate) fn strip_wpt_root_dir_prefix<'a>(
4037
&self,
4138
path: &'a Utf8Path,
42-
) -> Result<(TestScope, &'a Utf8Path), std::path::StripPrefixError> {
43-
let strip_prefix =
44-
|prefix, scope| path.strip_prefix(prefix).map(|stripped| (scope, stripped));
39+
) -> Result<(RootDir, &'a Utf8Path), std::path::StripPrefixError> {
40+
let strip_prefix = |prefix, root_dir| {
41+
path.strip_prefix(prefix)
42+
.map(|stripped| (root_dir, stripped))
43+
};
4544
match self {
4645
Browser::Firefox => {
47-
strip_prefix(SCOPE_DIR_FX_MOZILLA_STR, FirefoxTestScope::Mozilla.into()).or_else(
48-
|_| strip_prefix(SCOPE_DIR_FX_UPSTREAM_STR, FirefoxTestScope::Upstream.into()),
46+
strip_prefix(ROOT_DIR_FX_MOZILLA_STR, FirefoxRootDir::Mozilla.into()).or_else(
47+
|_| strip_prefix(ROOT_DIR_FX_UPSTREAM_STR, FirefoxRootDir::Upstream.into()),
4948
)
5049
}
51-
Browser::Servo => {
52-
strip_prefix(SCOPE_DIR_SERVO_WEBGPU_STR, ServoTestScope::WebGpu.into())
53-
}
50+
Browser::Servo => strip_prefix(ROOT_DIR_SERVO_WEBGPU_STR, ServoRootDir::WebGpu.into()),
5451
}
5552
}
5653
}
@@ -64,8 +61,8 @@ impl Browser {
6461
/// [`metadata::File`]: crate::wpt::metadata::File
6562
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
6663
pub(crate) struct TestPath<'a> {
67-
pub scope: TestScope,
68-
/// A relative offset into `scope`.
64+
pub root_dir: RootDir,
65+
/// A relative offset into `root_dir`.
6966
pub path: Cow<'a, Utf8Path>,
7067
/// The variant of this particular test from this test's source code. If set, you should be
7168
/// able to correlate this with
@@ -76,12 +73,12 @@ pub(crate) struct TestPath<'a> {
7673
pub variant: Option<Cow<'a, str>>,
7774
}
7875

79-
const SCOPE_DIR_FX_MOZILLA_STR: &str = "testing/web-platform/mozilla";
80-
const SCOPE_DIR_FX_MOZILLA_COMPONENTS: &[&str] = &["testing", "web-platform", "mozilla"];
81-
const SCOPE_DIR_FX_UPSTREAM_STR: &str = "testing/web-platform";
82-
const SCOPE_DIR_FX_UPSTREAM_COMPONENTS: &[&str] = &["testing", "web-platform"];
83-
const SCOPE_DIR_SERVO_WEBGPU_STR: &str = "tests/wpt/webgpu";
84-
const SCOPE_DIR_SERVO_WEBGPU_COMPONENTS: &[&str] = &["tests", "wpt", "webgpu"];
76+
const ROOT_DIR_FX_MOZILLA_STR: &str = "testing/web-platform/mozilla";
77+
const ROOT_DIR_FX_MOZILLA_COMPONENTS: &[&str] = &["testing", "web-platform", "mozilla"];
78+
const ROOT_DIR_FX_UPSTREAM_STR: &str = "testing/web-platform";
79+
const ROOT_DIR_FX_UPSTREAM_COMPONENTS: &[&str] = &["testing", "web-platform"];
80+
const ROOT_DIR_SERVO_WEBGPU_STR: &str = "tests/wpt/webgpu";
81+
const ROOT_DIR_SERVO_WEBGPU_COMPONENTS: &[&str] = &["tests", "wpt", "webgpu"];
8582

8683
impl<'a> TestPath<'a> {
8784
pub fn from_execution_report(
@@ -90,8 +87,8 @@ impl<'a> TestPath<'a> {
9087
) -> Result<Self, ExecutionReportPathError<'a>> {
9188
let err = || ExecutionReportPathError { test_url_path };
9289

93-
let (scope, path) = browser
94-
.strip_scope_url_prefix(test_url_path)
90+
let (root_dir, path) = browser
91+
.strip_wpt_url_prefix(test_url_path)
9592
.ok_or_else(err)?;
9693

9794
if path.contains('\\') {
@@ -110,7 +107,7 @@ impl<'a> TestPath<'a> {
110107
};
111108

112109
Ok(Self {
113-
scope,
110+
root_dir,
114111
path: Utf8Path::new(path).into(),
115112
variant: variant.map(Into::into),
116113
})
@@ -137,8 +134,8 @@ impl<'a> TestPath<'a> {
137134
.ok_or_else(err)?,
138135
);
139136

140-
let (scope, path) = browser
141-
.strip_scope_parent_path(rel_meta_file_path)
137+
let (root_dir, path) = browser
138+
.strip_wpt_root_dir_prefix(rel_meta_file_path)
142139
.map_err(|_e| err())?;
143140

144141
let Ok(path) = path.strip_prefix("meta/") else {
@@ -152,7 +149,7 @@ impl<'a> TestPath<'a> {
152149
}
153150

154151
Ok(Self {
155-
scope,
152+
root_dir,
156153
path: path.into(),
157154
variant: variant.map(Into::into),
158155
})
@@ -170,13 +167,13 @@ impl<'a> TestPath<'a> {
170167

171168
pub fn into_owned(self) -> TestPath<'static> {
172169
let Self {
173-
scope,
170+
root_dir,
174171
path,
175172
variant,
176173
} = self;
177174

178175
TestPath {
179-
scope: scope.clone(),
176+
root_dir: root_dir.clone(),
180177
path: path.clone().into_owned().into(),
181178
variant: variant.clone().map(|v| v.into_owned().into()),
182179
}
@@ -186,7 +183,7 @@ impl<'a> TestPath<'a> {
186183
let Self {
187184
path,
188185
variant,
189-
scope: _,
186+
root_dir: _,
190187
} = self;
191188
let base_name = path.file_name().unwrap();
192189

@@ -203,13 +200,13 @@ impl<'a> TestPath<'a> {
203200
let Self {
204201
path,
205202
variant,
206-
scope,
203+
root_dir,
207204
} = self;
208205
lazy_format!(move |f| {
209206
write!(
210207
f,
211208
"{}{}",
212-
scope.url_prefix(),
209+
root_dir.url_prefix(),
213210
path.components().join_with('/')
214211
)?;
215212
if let Some(variant) = variant.as_ref() {
@@ -223,15 +220,17 @@ impl<'a> TestPath<'a> {
223220
let Self {
224221
path,
225222
variant: _,
226-
scope,
223+
root_dir,
227224
} = self;
228225

229-
let scope_dir = scope
230-
.metadata_parent_path_components()
226+
let root_dir_dir = root_dir
227+
.components()
231228
.chain(["meta"].iter().cloned())
232229
.join_with(std::path::MAIN_SEPARATOR);
233230

234-
lazy_format!(move |f| { write!(f, "{scope_dir}{}{path}.ini", std::path::MAIN_SEPARATOR) })
231+
lazy_format!(move |f| {
232+
write!(f, "{root_dir_dir}{}{path}.ini", std::path::MAIN_SEPARATOR)
233+
})
235234
}
236235
}
237236

@@ -276,43 +275,42 @@ impl Display for MetadataTestPathError<'_> {
276275
}
277276
}
278277

279-
/// Symbolically represents a file root from which tests and metadata are based. Scopes are based
280-
/// on a specific [`Browser`].
278+
/// A root directory from which WPT tests and metadata are based. Based on a specific [`Browser`].
281279
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
282-
pub(crate) enum TestScope {
283-
Firefox(FirefoxTestScope),
284-
Servo(ServoTestScope),
280+
pub(crate) enum RootDir {
281+
Firefox(FirefoxRootDir),
282+
Servo(ServoRootDir),
285283
}
286284

287-
impl TestScope {
288-
/// NOTE: Keep this implementation in sync with [`Browser::strip_scope_url_prefix`].
285+
impl RootDir {
286+
/// NOTE: Keep this implementation in sync with [`Browser::strip_wpt_url_prefix`].
289287
fn url_prefix(&self) -> &str {
290288
match self {
291-
TestScope::Firefox(scope) => match scope {
292-
FirefoxTestScope::Upstream => "",
293-
FirefoxTestScope::Mozilla => "_mozilla/",
289+
RootDir::Firefox(root_dir) => match root_dir {
290+
FirefoxRootDir::Upstream => "",
291+
FirefoxRootDir::Mozilla => "_mozilla/",
294292
},
295-
TestScope::Servo(ServoTestScope::WebGpu) => "_webgpu/",
293+
RootDir::Servo(ServoRootDir::WebGpu) => "_webgpu/",
296294
}
297295
}
298296

299-
/// NOTE: Keep this implementation in sync with [`Browser::strip_scope_metadata_parent_path`].
300-
fn metadata_parent_path_components(&self) -> impl Iterator<Item = &str> + Clone {
297+
/// NOTE: Keep this implementation in sync with [`Browser::strip_wpt_root_dir_prefix`].
298+
fn components(&self) -> impl Iterator<Item = &str> + Clone {
301299
match self {
302-
TestScope::Firefox(scope) => match scope {
303-
FirefoxTestScope::Upstream => SCOPE_DIR_FX_UPSTREAM_COMPONENTS,
304-
FirefoxTestScope::Mozilla => SCOPE_DIR_FX_MOZILLA_COMPONENTS,
300+
RootDir::Firefox(root_dir) => match root_dir {
301+
FirefoxRootDir::Upstream => ROOT_DIR_FX_UPSTREAM_COMPONENTS,
302+
FirefoxRootDir::Mozilla => ROOT_DIR_FX_MOZILLA_COMPONENTS,
305303
},
306-
TestScope::Servo(ServoTestScope::WebGpu) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS,
304+
RootDir::Servo(ServoRootDir::WebGpu) => ROOT_DIR_SERVO_WEBGPU_COMPONENTS,
307305
}
308306
.iter()
309307
.cloned()
310308
}
311309
}
312310

313-
/// Subset of [`TestScope`] for [`Browser::Firefox`].
311+
/// Subset of [`RootDir`] for [`Browser::Firefox`].
314312
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
315-
pub(crate) enum FirefoxTestScope {
313+
pub(crate) enum FirefoxRootDir {
316314
/// A public test available at some point in the history of [WPT upstream]. Note that while
317315
/// a test may be public, metadata associated with it is in a private location.
318316
///
@@ -322,21 +320,21 @@ pub(crate) enum FirefoxTestScope {
322320
Mozilla,
323321
}
324322

325-
impl From<FirefoxTestScope> for TestScope {
326-
fn from(value: FirefoxTestScope) -> Self {
323+
impl From<FirefoxRootDir> for RootDir {
324+
fn from(value: FirefoxRootDir) -> Self {
327325
Self::Firefox(value)
328326
}
329327
}
330328

331-
/// Subset of [`TestScope`] for [`Browser::Servo`].
329+
/// Subset of [`RootDir`] for [`Browser::Servo`].
332330
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
333-
pub(crate) enum ServoTestScope {
331+
pub(crate) enum ServoRootDir {
334332
/// A WebGPU CTS test vendored into Servo's source tree.
335333
WebGpu,
336334
}
337335

338-
impl From<ServoTestScope> for TestScope {
339-
fn from(value: ServoTestScope) -> Self {
336+
impl From<ServoRootDir> for RootDir {
337+
fn from(value: ServoRootDir) -> Self {
340338
Self::Servo(value)
341339
}
342340
}
@@ -351,7 +349,7 @@ fn parse_test_path() {
351349
)
352350
.unwrap(),
353351
TestPath {
354-
scope: FirefoxTestScope::Mozilla.into(),
352+
root_dir: FirefoxRootDir::Mozilla.into(),
355353
path: Utf8Path::new("blarg/cts.https.html").into(),
356354
variant: Some("?stuff=things".into()),
357355
}
@@ -365,7 +363,7 @@ fn parse_test_path() {
365363
)
366364
.unwrap(),
367365
TestPath {
368-
scope: FirefoxTestScope::Upstream.into(),
366+
root_dir: FirefoxRootDir::Upstream.into(),
369367
path: Utf8Path::new("stuff/things/cts.https.html").into(),
370368
variant: None,
371369
}
@@ -379,7 +377,7 @@ fn parse_test_path() {
379377
)
380378
.unwrap(),
381379
TestPath {
382-
scope: ServoTestScope::WebGpu.into(),
380+
root_dir: ServoRootDir::WebGpu.into(),
383381
path: Utf8Path::new("webgpu/cts.https.html").into(),
384382
variant: Some("?stuff=things".into()),
385383
}

0 commit comments

Comments
 (0)