diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-03-22 20:50:59 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-03-22 20:52:47 -0300 |
commit | 5bb562ad496f9ec42ec59abfe31d3576266c6a6d (patch) | |
tree | 4c792fcc67d4211c6c5b4a0e18ebb832b0d4ce66 /tests |
Initial commit
Diffstat (limited to 'tests')
-rw-r--r-- | tests/01-parse-impl.rs | 12 | ||||
-rw-r--r-- | tests/02-not-impl.rs | 10 | ||||
-rw-r--r-- | tests/02-not-impl.stderr | 10 | ||||
-rw-r--r-- | tests/03-not-trait-impl.rs | 16 | ||||
-rw-r--r-- | tests/03-not-trait-impl.stderr | 10 | ||||
-rw-r--r-- | tests/04-generics.rs | 14 | ||||
-rw-r--r-- | tests/05-where.rs | 14 | ||||
-rw-r--r-- | tests/06-impl-trait.rs | 20 | ||||
-rw-r--r-- | tests/07-docs.rs | 21 | ||||
-rw-r--r-- | tests/08-inherent-docs.rs | 21 | ||||
-rw-r--r-- | tests/98-readme.rs | 20 | ||||
-rw-r--r-- | tests/99-goal.rs | 17 | ||||
-rw-r--r-- | tests/progress.rs | 14 |
13 files changed, 199 insertions, 0 deletions
diff --git a/tests/01-parse-impl.rs b/tests/01-parse-impl.rs new file mode 100644 index 0000000..8fe5b3c --- /dev/null +++ b/tests/01-parse-impl.rs @@ -0,0 +1,12 @@ +// Checks if #[impl_trait] exists. + +use impl_trait::impl_trait; + +struct Foo; + +impl_trait! { + impl Foo { + } +} + +fn main() {} diff --git a/tests/02-not-impl.rs b/tests/02-not-impl.rs new file mode 100644 index 0000000..3a14bae --- /dev/null +++ b/tests/02-not-impl.rs @@ -0,0 +1,10 @@ +// Checks that #[impl_trait] checks for impls. + +use impl_trait::impl_trait; + +impl_trait! { + struct Foo { + } +} + +fn main() {} diff --git a/tests/02-not-impl.stderr b/tests/02-not-impl.stderr new file mode 100644 index 0000000..a81e390 --- /dev/null +++ b/tests/02-not-impl.stderr @@ -0,0 +1,10 @@ +error: proc macro panicked + --> $DIR/02-not-impl.rs:5:1 + | +5 | / impl_trait! { +6 | | struct Foo { +7 | | } +8 | | } + | |_^ + | + = help: message: impl_trait! may only be applied to inherent impls diff --git a/tests/03-not-trait-impl.rs b/tests/03-not-trait-impl.rs new file mode 100644 index 0000000..0b05145 --- /dev/null +++ b/tests/03-not-trait-impl.rs @@ -0,0 +1,16 @@ +// Checks that #[impl_trait] doesn't work on a trait impl. + +use impl_trait::impl_trait; + +struct Foo { +} + +trait Bar { +} + +impl_trait! { + impl Bar for Foo { + } +} + +fn main() {} diff --git a/tests/03-not-trait-impl.stderr b/tests/03-not-trait-impl.stderr new file mode 100644 index 0000000..8206f00 --- /dev/null +++ b/tests/03-not-trait-impl.stderr @@ -0,0 +1,10 @@ +error: proc macro panicked + --> $DIR/03-not-trait-impl.rs:11:1 + | +11 | / impl_trait! { +12 | | impl Bar for Foo { +13 | | } +14 | | } + | |_^ + | + = help: message: impl_trait! may only be applied to inherent impls diff --git a/tests/04-generics.rs b/tests/04-generics.rs new file mode 100644 index 0000000..eefeff2 --- /dev/null +++ b/tests/04-generics.rs @@ -0,0 +1,14 @@ +// Checks that #[impl_trait] works with generics. + +use impl_trait::impl_trait; + +struct Foo<T>(T); +trait Bar { +} + +impl_trait! { + impl<T> Foo<T> { + } +} + +fn main() {} diff --git a/tests/05-where.rs b/tests/05-where.rs new file mode 100644 index 0000000..c37db6c --- /dev/null +++ b/tests/05-where.rs @@ -0,0 +1,14 @@ +// Checks that #[impl_trait] works with generics. + +use impl_trait::impl_trait; + +struct Foo<T>(T); +trait Bar { +} + +impl_trait! { + impl<T> Foo<T> where T: Default { + } +} + +fn main() {} diff --git a/tests/06-impl-trait.rs b/tests/06-impl-trait.rs new file mode 100644 index 0000000..ca0d2ee --- /dev/null +++ b/tests/06-impl-trait.rs @@ -0,0 +1,20 @@ +// Checks that `impl trait` works. + +use impl_trait::impl_trait; + +struct Foo; +trait Bar { +} + +impl_trait! { + impl Foo { + impl trait Bar { + } + } +} + +fn static_assert<T: Bar>(_t: T) {} + +fn main() { + static_assert(Foo); +} diff --git a/tests/07-docs.rs b/tests/07-docs.rs new file mode 100644 index 0000000..a26bf50 --- /dev/null +++ b/tests/07-docs.rs @@ -0,0 +1,21 @@ +// Checks that `impl trait` works, with docs. + +use impl_trait::impl_trait; + +struct Foo; +trait Bar { +} + +impl_trait! { + impl Foo { + /// More test docs + impl trait Bar { + } + } +} + +fn static_assert<T: Bar>(_t: T) {} + +fn main() { + static_assert(Foo); +} diff --git a/tests/08-inherent-docs.rs b/tests/08-inherent-docs.rs new file mode 100644 index 0000000..162bad3 --- /dev/null +++ b/tests/08-inherent-docs.rs @@ -0,0 +1,21 @@ +// Checks that `impl trait` works, with docs. + +use impl_trait::impl_trait; + +struct Foo; +trait Bar { +} + +impl_trait! { + /// Test docs + impl Foo { + impl trait Bar { + } + } +} + +fn static_assert<T: Bar>(_t: T) {} + +fn main() { + static_assert(Foo); +} diff --git a/tests/98-readme.rs b/tests/98-readme.rs new file mode 100644 index 0000000..bad1f34 --- /dev/null +++ b/tests/98-readme.rs @@ -0,0 +1,20 @@ +use impl_trait::impl_trait; + +struct Foo; + +trait Bar {} + +impl_trait! { + /// Yes, you can write docs here. + impl Foo { + /// You can write docs here too. + fn as_dyn_bar(&self) -> &dyn Bar { + self + } + /// You can even write docs here! + impl trait Bar { + } + } +} + +fn main() {} diff --git a/tests/99-goal.rs b/tests/99-goal.rs new file mode 100644 index 0000000..117d70b --- /dev/null +++ b/tests/99-goal.rs @@ -0,0 +1,17 @@ +// Checks that #[impl_trait] works with generics. + +use impl_trait::impl_trait; + +struct Foo<T>(T); + +impl_trait! { + impl<T> Foo<T> where T: Default { + impl trait Default { + fn default() -> Self { + Self(T::default()) + } + } + } +} + +fn main() {} diff --git a/tests/progress.rs b/tests/progress.rs new file mode 100644 index 0000000..aa42baa --- /dev/null +++ b/tests/progress.rs @@ -0,0 +1,14 @@ +#[test] +fn tests() { + let t = trybuild::TestCases::new(); + t.pass("tests/01-parse-impl.rs"); + t.compile_fail("tests/02-not-impl.rs"); + t.compile_fail("tests/03-not-trait-impl.rs"); + t.pass("tests/04-generics.rs"); + t.pass("tests/05-where.rs"); + t.pass("tests/06-impl-trait.rs"); + t.pass("tests/07-docs.rs"); + t.pass("tests/08-inherent-docs.rs"); + t.pass("tests/98-readme.rs"); + t.pass("tests/99-goal.rs"); +} |