Skip to content

Commit cf6b3b8

Browse files
move: break out disabled_string module
1 parent 023adc1 commit cf6b3b8

2 files changed

Lines changed: 66 additions & 57 deletions

File tree

moz-webgpu-cts/src/wpt/metadata/properties.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
borrow::Cow,
32
collections::BTreeMap,
43
fmt::{self, Debug, Display, Formatter},
54
num::NonZeroUsize,
@@ -13,6 +12,10 @@ use serde::Serialize;
1312

1413
use crate::wpt::metadata::{maybe_collapsed::MaybeCollapsed, BuildProfile, Platform};
1514

15+
pub use self::disabled_string::DisabledString;
16+
17+
mod disabled_string;
18+
1619
/// A non-empty set of expected outcomes in a [`Test`] or [`Subtest`].
1720
///
1821
/// The default expected test outcome is a "good" outcome, where testing passes. The `Out` type
@@ -207,62 +210,6 @@ where
207210

208211
impl<Out> Eq for Expected<Out> where Out: EnumSetType + Eq {}
209212

210-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
211-
pub struct DisabledString(Cow<'static, str>);
212-
213-
impl DisabledString {
214-
const FALSE: &'static str = "@False";
215-
216-
pub fn new(inner: String) -> Self {
217-
Self(if inner == Self::FALSE {
218-
// OPT: It can be expensive to store `Default`-generated copies of this, so let's avoid
219-
// heap allocations for this case specifically.
220-
Self::FALSE.into()
221-
} else {
222-
inner.into()
223-
})
224-
}
225-
226-
fn value(&self) -> &str {
227-
self.0.as_ref()
228-
}
229-
230-
pub fn is_disabled(&self) -> bool {
231-
self.value() != Self::FALSE
232-
}
233-
}
234-
235-
impl Default for DisabledString {
236-
fn default() -> Self {
237-
Self::new(Self::FALSE.into())
238-
}
239-
}
240-
241-
impl Display for DisabledString {
242-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
243-
Display::fmt(self.value(), f)
244-
}
245-
}
246-
247-
#[test]
248-
fn disabled_string() {
249-
let asdf = DisabledString::new("asdf".into());
250-
assert_eq!(asdf, DisabledString("asdf".to_string().into()));
251-
assert_eq!(asdf.value(), "asdf");
252-
253-
assert_eq!(
254-
&DisabledString::new("@False".into()).0,
255-
&DisabledString::FALSE
256-
);
257-
258-
assert!(!DisabledString::new(DisabledString::FALSE.into()).is_disabled());
259-
assert!(DisabledString::new("asdf".into()).is_disabled());
260-
assert!(
261-
DisabledString::new("https://bugzilla.mozilla.org/show_bug.cgi?id=1958061".into())
262-
.is_disabled()
263-
);
264-
}
265-
266213
/// A completely flat representation of [`NormalizedPropertyValue`] suitable for byte
267214
/// representation in memory.
268215
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize)]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::{
2+
borrow::Cow,
3+
fmt::{self, Display, Formatter},
4+
};
5+
6+
use serde::Serialize;
7+
8+
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
9+
pub struct DisabledString(Cow<'static, str>);
10+
11+
impl DisabledString {
12+
const FALSE: &'static str = "@False";
13+
14+
pub fn new(inner: String) -> Self {
15+
Self(if inner == Self::FALSE {
16+
// OPT: It can be expensive to store `Default`-generated copies of this, so let's avoid
17+
// heap allocations for this case specifically.
18+
Self::FALSE.into()
19+
} else {
20+
inner.into()
21+
})
22+
}
23+
24+
fn value(&self) -> &str {
25+
self.0.as_ref()
26+
}
27+
28+
pub fn is_disabled(&self) -> bool {
29+
self.value() != Self::FALSE
30+
}
31+
}
32+
33+
impl Default for DisabledString {
34+
fn default() -> Self {
35+
Self::new(Self::FALSE.into())
36+
}
37+
}
38+
39+
impl Display for DisabledString {
40+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
41+
Display::fmt(self.value(), f)
42+
}
43+
}
44+
45+
#[test]
46+
fn disabled_string() {
47+
let asdf = DisabledString::new("asdf".into());
48+
assert_eq!(asdf, DisabledString("asdf".to_string().into()));
49+
assert_eq!(asdf.value(), "asdf");
50+
51+
assert_eq!(
52+
&DisabledString::new("@False".into()).0,
53+
&DisabledString::FALSE
54+
);
55+
56+
assert!(!DisabledString::new(DisabledString::FALSE.into()).is_disabled());
57+
assert!(DisabledString::new("asdf".into()).is_disabled());
58+
assert!(
59+
DisabledString::new("https://bugzilla.mozilla.org/show_bug.cgi?id=1958061".into())
60+
.is_disabled()
61+
);
62+
}

0 commit comments

Comments
 (0)