Skip to content

Commit 8a6f5e3

Browse files
committed
Move construction tests into a test
1 parent f125094 commit 8a6f5e3

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/traits.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,3 @@ impl TextSized for char {
3434
(self.len_utf8() as u32).into()
3535
}
3636
}
37-
38-
// assertion shape from static_assertions::assert_impl_all!
39-
const _: fn() = || {
40-
use std::borrow::Cow;
41-
42-
fn assert_impl<T: TextSized>() {}
43-
44-
assert_impl::<&String>();
45-
assert_impl::<&Cow<str>>();
46-
47-
struct StringLike {}
48-
impl Deref for StringLike {
49-
type Target = str;
50-
fn deref(&self) -> &str {
51-
unreachable!()
52-
}
53-
}
54-
55-
assert_impl::<&StringLike>();
56-
};

tests/constructors.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use {
2+
std::{borrow::Cow, ops::Deref},
3+
text_size::*,
4+
};
5+
6+
struct StringLike<'a>(&'a str);
7+
8+
impl Deref for StringLike<'_> {
9+
type Target = str;
10+
fn deref(&self) -> &Self::Target {
11+
&self.0
12+
}
13+
}
14+
15+
#[test]
16+
fn main() {
17+
let s = "";
18+
let _ = TextSize::of(&s);
19+
20+
let s = String::new();
21+
let _ = TextSize::of(&s);
22+
23+
let s = Cow::Borrowed("");
24+
let _ = TextSize::of(&s);
25+
26+
let s = Cow::Owned(String::new());
27+
let _ = TextSize::of(&s);
28+
29+
let s = StringLike("");
30+
let _ = TextSize::of(&s);
31+
}

0 commit comments

Comments
 (0)