summaryrefslogtreecommitdiffstats
path: root/third_party/rust/paste/tests
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/paste/tests')
-rw-r--r--third_party/rust/paste/tests/compiletest.rs6
-rw-r--r--third_party/rust/paste/tests/test.rs307
-rw-r--r--third_party/rust/paste/tests/ui/case-warning.rs13
-rw-r--r--third_party/rust/paste/tests/ui/case-warning.stderr16
-rw-r--r--third_party/rust/paste/tests/ui/no-env-var.rs5
-rw-r--r--third_party/rust/paste/tests/ui/no-env-var.stderr5
-rw-r--r--third_party/rust/paste/tests/ui/unexpected-modifier.rs5
-rw-r--r--third_party/rust/paste/tests/ui/unexpected-modifier.stderr5
-rw-r--r--third_party/rust/paste/tests/ui/unsupported-modifier.rs5
-rw-r--r--third_party/rust/paste/tests/ui/unsupported-modifier.stderr5
10 files changed, 372 insertions, 0 deletions
diff --git a/third_party/rust/paste/tests/compiletest.rs b/third_party/rust/paste/tests/compiletest.rs
new file mode 100644
index 0000000000..f9aea23b51
--- /dev/null
+++ b/third_party/rust/paste/tests/compiletest.rs
@@ -0,0 +1,6 @@
+#[rustversion::attr(not(nightly), ignore)]
+#[test]
+fn ui() {
+ let t = trybuild::TestCases::new();
+ t.compile_fail("tests/ui/*.rs");
+}
diff --git a/third_party/rust/paste/tests/test.rs b/third_party/rust/paste/tests/test.rs
new file mode 100644
index 0000000000..3aecd8d8e9
--- /dev/null
+++ b/third_party/rust/paste/tests/test.rs
@@ -0,0 +1,307 @@
+mod test_basic {
+ struct Struct;
+
+ paste::item! {
+ impl Struct {
+ fn [<a b c>]() {}
+ }
+ }
+
+ #[test]
+ fn test() {
+ Struct::abc();
+ }
+}
+
+mod test_in_impl {
+ struct Struct;
+
+ impl Struct {
+ paste::item! {
+ fn [<a b c>]() {}
+ }
+ }
+
+ #[test]
+ fn test() {
+ Struct::abc();
+ }
+}
+
+#[test]
+fn test_shared_hygiene() {
+ paste::expr! {
+ let [<a a>] = 1;
+ assert_eq!([<a a>], 1);
+ }
+}
+
+#[test]
+fn test_repeat() {
+ const ROCKET_A: &'static str = "/a";
+ const ROCKET_B: &'static str = "/b";
+
+ macro_rules! routes {
+ ($($route:ident),*) => {{
+ paste::expr! {
+ vec![$( [<ROCKET_ $route>] ),*]
+ }
+ }}
+ }
+
+ let routes = routes!(A, B);
+ assert_eq!(routes, vec!["/a", "/b"]);
+}
+
+#[test]
+fn test_integer() {
+ const CONST0: &'static str = "const0";
+
+ let pasted = paste::expr!([<CONST 0>]);
+ assert_eq!(pasted, CONST0);
+}
+
+#[test]
+fn test_underscore() {
+ paste::expr! {
+ const A_B: usize = 0;
+ assert_eq!([<A _ B>], 0);
+ }
+}
+
+#[test]
+fn test_lifetime() {
+ paste::expr! {
+ #[allow(dead_code)]
+ struct S<[<'d e>]> {
+ q: &[<'d e>] str,
+ }
+ }
+}
+
+#[test]
+fn test_keyword() {
+ paste::expr! {
+ struct [<F move>];
+
+ let _ = Fmove;
+ }
+}
+
+#[test]
+fn test_literal_str() {
+ paste::expr! {
+ struct [<Foo "Bar-Baz">];
+
+ let _ = FooBar_Baz;
+ }
+}
+
+#[test]
+fn test_env_literal() {
+ paste::expr! {
+ struct [<Lib env bar>];
+
+ let _ = Libenvbar;
+ }
+}
+
+#[test]
+fn test_env_present() {
+ paste::expr! {
+ struct [<Lib env!("CARGO_PKG_NAME")>];
+
+ let _ = Libpaste;
+ }
+}
+
+#[test]
+fn test_raw_identifier() {
+ paste::expr! {
+ struct [<F r#move>];
+
+ let _ = Fmove;
+ }
+}
+
+#[test]
+fn test_false_start() {
+ trait Trait {
+ fn f() -> usize;
+ }
+
+ struct S;
+
+ impl Trait for S {
+ fn f() -> usize {
+ 0
+ }
+ }
+
+ paste::expr! {
+ let x = [<S as Trait>::f()];
+ assert_eq!(x[0], 0);
+ }
+}
+
+#[test]
+fn test_local_variable() {
+ let yy = 0;
+
+ paste::expr! {
+ assert_eq!([<y y>], 0);
+ }
+}
+
+mod test_none_delimited_single_ident {
+ macro_rules! m {
+ ($id:ident) => {
+ paste::item! {
+ fn f() -> &'static str {
+ stringify!($id)
+ }
+ }
+ };
+ }
+
+ m!(i32x4);
+
+ #[test]
+ fn test() {
+ assert_eq!(f(), "i32x4");
+ }
+}
+
+mod test_none_delimited_single_lifetime {
+ macro_rules! m {
+ ($life:lifetime) => {
+ paste::item! {
+ pub struct S;
+ impl<$life> S {
+ fn f() {}
+ }
+ }
+ };
+ }
+
+ m!('a);
+
+ #[test]
+ fn test() {
+ S::f();
+ }
+}
+
+mod test_to_lower {
+ macro_rules! m {
+ ($id:ident) => {
+ paste::item! {
+ fn [<my_ $id:lower _here>](_arg: u8) -> &'static str {
+ stringify!([<$id:lower>])
+ }
+ }
+ };
+ }
+
+ m!(Test);
+
+ #[test]
+ fn test_to_lower() {
+ assert_eq!(my_test_here(0), "test");
+ }
+}
+
+#[test]
+fn test_env_to_lower() {
+ paste::expr! {
+ struct [<Lib env!("CARGO_PKG_NAME"):lower>];
+
+ let _ = Libpaste;
+ }
+}
+
+mod test_to_upper {
+ macro_rules! m {
+ ($id:ident) => {
+ paste::item! {
+ const [<MY_ $id:upper _HERE>]: &str = stringify!([<$id:upper>]);
+ }
+ };
+ }
+
+ m!(Test);
+
+ #[test]
+ fn test_to_upper() {
+ assert_eq!(MY_TEST_HERE, "TEST");
+ }
+}
+
+#[test]
+fn test_env_to_upper() {
+ paste::expr! {
+ const [<LIB env!("CARGO_PKG_NAME"):upper>]: &str = "libpaste";
+
+ let _ = LIBPASTE;
+ }
+}
+
+mod test_to_snake {
+ macro_rules! m {
+ ($id:ident) => {
+ paste::item! {
+ const DEFAULT_SNAKE: &str = stringify!([<$id:snake>]);
+ const LOWER_SNAKE: &str = stringify!([<$id:snake:lower>]);
+ const UPPER_SNAKE: &str = stringify!([<$id:snake:upper>]);
+ }
+ };
+ }
+
+ m!(ThisIsButATest);
+
+ #[test]
+ fn test_to_snake() {
+ assert_eq!(DEFAULT_SNAKE, "this_is_but_a_test");
+ assert_eq!(LOWER_SNAKE, "this_is_but_a_test");
+ assert_eq!(UPPER_SNAKE, "THIS_IS_BUT_A_TEST");
+ }
+}
+
+#[test]
+fn test_env_to_snake() {
+ paste::expr! {
+ const [<LIB env!("CARGO_PKG_NAME"):snake:upper>]: &str = "libpaste";
+
+ let _ = LIBPASTE;
+ }
+}
+
+mod test_to_camel {
+ macro_rules! m {
+ ($id:ident) => {
+ paste::item! {
+ const DEFAULT_CAMEL: &str = stringify!([<$id:camel>]);
+ const LOWER_CAMEL: &str = stringify!([<$id:camel:lower>]);
+ const UPPER_CAMEL: &str = stringify!([<$id:camel:upper>]);
+ }
+ };
+ }
+
+ m!(this_is_but_a_test);
+
+ #[test]
+ fn test_to_camel() {
+ assert_eq!(DEFAULT_CAMEL, "ThisIsButATest");
+ assert_eq!(LOWER_CAMEL, "thisisbutatest");
+ assert_eq!(UPPER_CAMEL, "THISISBUTATEST");
+ }
+}
+
+#[test]
+fn test_env_to_camel() {
+ paste::expr! {
+ const [<LIB env!("CARGO_PKG_NAME"):camel>]: &str = "libpaste";
+
+ let _ = LIBPaste;
+ }
+}
diff --git a/third_party/rust/paste/tests/ui/case-warning.rs b/third_party/rust/paste/tests/ui/case-warning.rs
new file mode 100644
index 0000000000..4b41ab683d
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/case-warning.rs
@@ -0,0 +1,13 @@
+#![deny(warnings)]
+
+macro_rules! m {
+ ($i:ident) => {
+ paste::item! {
+ pub fn [<foo $i>]() {}
+ }
+ };
+}
+
+m!(Bar);
+
+fn main() {}
diff --git a/third_party/rust/paste/tests/ui/case-warning.stderr b/third_party/rust/paste/tests/ui/case-warning.stderr
new file mode 100644
index 0000000000..5bf37a083c
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/case-warning.stderr
@@ -0,0 +1,16 @@
+error: function `fooBar` should have a snake case name
+ --> $DIR/case-warning.rs:6:20
+ |
+6 | pub fn [<foo $i>]() {}
+ | ^^^^^^^^^^ help: convert the identifier to snake case: `foo_bar`
+...
+11 | m!(Bar);
+ | -------- in this macro invocation
+ |
+note: the lint level is defined here
+ --> $DIR/case-warning.rs:1:9
+ |
+1 | #![deny(warnings)]
+ | ^^^^^^^^
+ = note: `#[deny(non_snake_case)]` implied by `#[deny(warnings)]`
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/third_party/rust/paste/tests/ui/no-env-var.rs b/third_party/rust/paste/tests/ui/no-env-var.rs
new file mode 100644
index 0000000000..87aad35091
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/no-env-var.rs
@@ -0,0 +1,5 @@
+paste::item! {
+ fn [<a env!("PASTE_UNKNOWN") b>]() {}
+}
+
+fn main() {}
diff --git a/third_party/rust/paste/tests/ui/no-env-var.stderr b/third_party/rust/paste/tests/ui/no-env-var.stderr
new file mode 100644
index 0000000000..2ec206d665
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/no-env-var.stderr
@@ -0,0 +1,5 @@
+error: no such env var
+ --> $DIR/no-env-var.rs:2:17
+ |
+2 | fn [<a env!("PASTE_UNKNOWN") b>]() {}
+ | ^^^^^^^^^^^^^^^
diff --git a/third_party/rust/paste/tests/ui/unexpected-modifier.rs b/third_party/rust/paste/tests/ui/unexpected-modifier.rs
new file mode 100644
index 0000000000..00a1e99c6d
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/unexpected-modifier.rs
@@ -0,0 +1,5 @@
+paste::item! {
+ fn [<:lower x>]() {}
+}
+
+fn main() {}
diff --git a/third_party/rust/paste/tests/ui/unexpected-modifier.stderr b/third_party/rust/paste/tests/ui/unexpected-modifier.stderr
new file mode 100644
index 0000000000..4a518b8ea8
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/unexpected-modifier.stderr
@@ -0,0 +1,5 @@
+error: unexpected modifier
+ --> $DIR/unexpected-modifier.rs:2:10
+ |
+2 | fn [<:lower x>]() {}
+ | ^^^^^^
diff --git a/third_party/rust/paste/tests/ui/unsupported-modifier.rs b/third_party/rust/paste/tests/ui/unsupported-modifier.rs
new file mode 100644
index 0000000000..5ab049fbb1
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/unsupported-modifier.rs
@@ -0,0 +1,5 @@
+paste::item! {
+ fn [<a:pillow>]() {}
+}
+
+fn main() {}
diff --git a/third_party/rust/paste/tests/ui/unsupported-modifier.stderr b/third_party/rust/paste/tests/ui/unsupported-modifier.stderr
new file mode 100644
index 0000000000..ffbc742a29
--- /dev/null
+++ b/third_party/rust/paste/tests/ui/unsupported-modifier.stderr
@@ -0,0 +1,5 @@
+error: unsupported modifier
+ --> $DIR/unsupported-modifier.rs:2:11
+ |
+2 | fn [<a:pillow>]() {}
+ | ^^^^^^^