diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/extend/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/extend/tests')
21 files changed, 379 insertions, 0 deletions
diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.rs b/third_party/rust/extend/tests/compile_fail/double_vis.rs new file mode 100644 index 0000000000..4e0e135ad3 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/double_vis.rs @@ -0,0 +1,14 @@ +mod a { + use extend::ext; + + #[ext(pub(super))] + pub impl i32 { + fn foo() -> Foo { + Foo + } + } + + pub struct Foo; +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.stderr b/third_party/rust/extend/tests/compile_fail/double_vis.stderr new file mode 100644 index 0000000000..c98b614935 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/double_vis.stderr @@ -0,0 +1,5 @@ +error: Cannot set visibility on `#[ext]` and `impl` block + --> $DIR/double_vis.rs:4:11 + | +4 | #[ext(pub(super))] + | ^^^ diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs new file mode 100644 index 0000000000..5fba303138 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs @@ -0,0 +1,14 @@ +use extend::ext; + +trait MyTrait {} + +#[ext(supertraits = MyTrait)] +impl String { + fn my_len(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(String::new().my_len(), 0); +} diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr new file mode 100644 index 0000000000..60059f73fb --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr @@ -0,0 +1,10 @@ +error[E0277]: the trait bound `String: MyTrait` is not satisfied + --> $DIR/supertraits_are_actually_included.rs:6:6 + | +5 | #[ext(supertraits = MyTrait)] + | ------- required by this bound in `StringExt` +6 | impl String { + | ^^^^^^ + | | + | the trait `MyTrait` is not implemented for `String` + | required by a bound in this diff --git a/third_party/rust/extend/tests/compile_pass/associated_constants.rs b/third_party/rust/extend/tests/compile_pass/associated_constants.rs new file mode 100644 index 0000000000..5cb982c6a4 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/associated_constants.rs @@ -0,0 +1,10 @@ +use extend::ext; + +#[ext] +impl Option<String> { + const FOO: usize = 1; +} + +fn main() { + assert_eq!(Option::<String>::FOO, 1); +} diff --git a/third_party/rust/extend/tests/compile_pass/async_trait.rs b/third_party/rust/extend/tests/compile_pass/async_trait.rs new file mode 100644 index 0000000000..067bdc9bb7 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/async_trait.rs @@ -0,0 +1,25 @@ +use extend::ext; +use async_trait::async_trait; + +#[ext] +#[async_trait] +impl String { + async fn foo() -> usize { + 1 + } +} + +#[ext] +#[async_trait] +pub impl i32 { + async fn bar() -> usize { + 1 + } +} + +async fn foo() { + let _: usize = String::foo().await; + let _: usize = i32::bar().await; +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs b/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs new file mode 100644 index 0000000000..fc83b19339 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs @@ -0,0 +1,10 @@ +use extend::ext; + +#[ext(name = Foo)] +impl i32 { + fn foo() {} +} + +fn main() { + <i32 as Foo>::foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs b/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs new file mode 100644 index 0000000000..3457495132 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs @@ -0,0 +1,16 @@ +mod foo { + use extend::ext; + + #[ext(pub)] + impl<T1, T2, T3> (T1, T2, T3) { + fn size(&self) -> usize { + 3 + } + } +} + +fn main() { + use foo::TupleOfT1T2T3Ext; + + assert_eq!(3, (0, 0, 0).size()); +} diff --git a/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs b/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs new file mode 100644 index 0000000000..972d530fa8 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs @@ -0,0 +1,17 @@ +use extend::ext; + +#[ext] +impl Option<usize> { + fn foo() -> usize { + 1 + } +} + +#[ext] +impl Option<i32> { + fn bar() -> i32 { + 1 + } +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs b/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs new file mode 100644 index 0000000000..20dfb7ca90 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs @@ -0,0 +1,58 @@ +use extend::ext; + +#[ext] +impl<'a> &'a str { + fn foo(self) {} +} + +#[ext] +impl<T> [T; 3] { + fn foo(self) {} +} + +#[ext] +impl *const i32 { + fn foo(self) {} +} + +#[ext] +impl<T> [T] { + fn foo(&self) {} +} + +#[ext] +impl<'a, T> &'a [T] { + fn foo(self) {} +} + +#[ext] +impl (i32, i64) { + fn foo(self) {} +} + +#[ext] +impl fn(i32) -> bool { + fn foo(self) {} +} + +fn bare_fn(_: i32) -> bool { + false +} + +#[ext] +impl dyn Send + Sync + 'static {} + +fn main() { + "".foo(); + + [1, 2, 3].foo(); + + let ptr: *const i32 = &123; + ptr.foo(); + + &[1, 2, 3].foo(); + + (1i32, 1i64).foo(); + + (bare_fn as fn(i32) -> bool).foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/generics.rs b/third_party/rust/extend/tests/compile_pass/generics.rs new file mode 100644 index 0000000000..4c56b14677 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/generics.rs @@ -0,0 +1,15 @@ +use extend::ext; + +#[ext] +impl<'a, T: Clone> Vec<&'a T> +where + T: 'a + Copy, +{ + fn size(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(3, vec![&1, &2, &3].size()); +} diff --git a/third_party/rust/extend/tests/compile_pass/hello_world.rs b/third_party/rust/extend/tests/compile_pass/hello_world.rs new file mode 100644 index 0000000000..75c61183b4 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/hello_world.rs @@ -0,0 +1,20 @@ +use extend::ext; + +#[ext] +impl i32 { + fn add_one(&self) -> Self { + self + 1 + } + + fn foo() -> MyType { + MyType + } +} + +#[derive(Debug, Eq, PartialEq)] +struct MyType; + +fn main() { + assert_eq!(i32::foo(), MyType); + assert_eq!(1.add_one(), 2); +} diff --git a/third_party/rust/extend/tests/compile_pass/issue_2.rs b/third_party/rust/extend/tests/compile_pass/issue_2.rs new file mode 100644 index 0000000000..76516486ab --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/issue_2.rs @@ -0,0 +1,33 @@ +#![allow(unused_variables)] + +use extend::ext; +use std::iter::FromIterator; + +#[ext] +impl<T, K, F, C> C +where + C: IntoIterator<Item = T>, + K: Eq, + F: Fn(&T) -> K, +{ + fn group_by<Out>(self, f: F) -> Out + where + Out: FromIterator<(K, Vec<T>)>, + { + todo!() + } + + fn group_by_and_map_values<Out, G, T2>(self, f: F, g: G) -> Out + where + G: Fn(T) -> T2 + Copy, + Out: FromIterator<(K, Vec<T2>)>, + { + todo!() + } + + fn group_by_and_return_groups(self, f: F) -> Vec<Vec<T>> { + todo!() + } +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs b/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs new file mode 100644 index 0000000000..e5ce539f15 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext] +impl i32 { + fn foo() {} +} + +#[ext] +impl i64 { + fn bar() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_config.rs b/third_party/rust/extend/tests/compile_pass/multiple_config.rs new file mode 100644 index 0000000000..9ffdad1316 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/multiple_config.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext(pub(crate), name = Foo)] +impl i32 { + fn foo() {} +} + +#[ext(pub, name = Bar)] +impl i64 { + fn foo() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs b/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs new file mode 100644 index 0000000000..29e4b9ca21 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs @@ -0,0 +1,11 @@ +use extend::ext; +use std::marker::PhantomData; + +struct Foo<T>(PhantomData<T>); + +#[ext] +impl<T, K> T { + fn some_method(&self, _: Foo<K>) {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/pub_impl.rs b/third_party/rust/extend/tests/compile_pass/pub_impl.rs new file mode 100644 index 0000000000..f7bff519c0 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/pub_impl.rs @@ -0,0 +1,15 @@ +mod a { + use extend::ext; + + #[ext] + pub impl i32 { + fn foo() -> Foo { Foo } + } + + pub struct Foo; +} + +fn main() { + use a::i32Ext; + i32::foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs b/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs new file mode 100644 index 0000000000..156f62027d --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext] +impl &i32 { + fn foo() {} +} + +#[ext] +impl &mut i32 { + fn bar() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/sized.rs b/third_party/rust/extend/tests/compile_pass/sized.rs new file mode 100644 index 0000000000..dae05f3f52 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/sized.rs @@ -0,0 +1,36 @@ +use extend::ext_sized; + +#[ext_sized(name = One)] +impl i32 { + fn requires_sized(self) -> Option<Self> { + Some(self) + } +} + +#[ext_sized(name = Two, supertraits = Default)] +impl i32 { + fn with_another_supertrait(self) -> Option<Self> { + Some(self) + } +} + +#[ext_sized(name = Three, supertraits = Default + Clone + Copy)] +impl i32 { + fn multiple_supertraits(self) -> Option<Self> { + Some(self) + } +} + +#[ext_sized(name = Four, supertraits = Sized)] +impl i32 { + fn already_sized(self) -> Option<Self> { + Some(self) + } +} + +fn main() { + 1.requires_sized(); + 1.with_another_supertrait(); + 1.multiple_supertraits(); + 1.already_sized(); +} diff --git a/third_party/rust/extend/tests/compile_pass/super_trait.rs b/third_party/rust/extend/tests/compile_pass/super_trait.rs new file mode 100644 index 0000000000..30b147d24a --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/super_trait.rs @@ -0,0 +1,16 @@ +use extend::ext; + +trait MyTrait {} + +impl MyTrait for String {} + +#[ext(supertraits = Default + Clone + MyTrait)] +impl String { + fn my_len(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(String::new().my_len(), 0); +} diff --git a/third_party/rust/extend/tests/compile_pass/visibility_config.rs b/third_party/rust/extend/tests/compile_pass/visibility_config.rs new file mode 100644 index 0000000000..bcb8b19576 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/visibility_config.rs @@ -0,0 +1,15 @@ +mod a { + use extend::ext; + + #[ext(pub)] + impl i32 { + fn foo() -> Foo { Foo } + } + + pub struct Foo; +} + +fn main() { + use a::i32Ext; + i32::foo(); +} |