aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2022-12-13 09:39:05 +0100
committerJeff Vander Stoep <jeffv@google.com>2022-12-13 09:39:48 +0100
commit83f7ae1e164d134fdd0379e30a500b5c6adfdfa0 (patch)
treed55cd2272eea8a02740a628f3d81dad893c930ed /tests
parent29c192030cca103c05a7b40d7a0c950120ffdccc (diff)
downloadpaste-83f7ae1e164d134fdd0379e30a500b5c6adfdfa0.tar.gz
Upgrade paste to 1.0.10
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/paste For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I9ad982c3a32bde1bc4328094f2a60c135c7cd0d4
Diffstat (limited to 'tests')
-rw-r--r--tests/compiletest.rs1
-rw-r--r--tests/test_expr.rs48
-rw-r--r--tests/test_item.rs4
-rw-r--r--tests/ui/invalid-ident.rs8
-rw-r--r--tests/ui/invalid-ident.stderr24
-rw-r--r--tests/ui/unsupported-literal.rs16
-rw-r--r--tests/ui/unsupported-literal.stderr24
7 files changed, 114 insertions, 11 deletions
diff --git a/tests/compiletest.rs b/tests/compiletest.rs
index f9aea23..7974a62 100644
--- a/tests/compiletest.rs
+++ b/tests/compiletest.rs
@@ -1,4 +1,5 @@
#[rustversion::attr(not(nightly), ignore)]
+#[cfg_attr(miri, ignore)]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
index a61bd03..41d84ce 100644
--- a/tests/test_expr.rs
+++ b/tests/test_expr.rs
@@ -26,11 +26,34 @@ fn test_repeat() {
}
#[test]
-fn test_integer() {
+fn test_literal_to_identifier() {
const CONST0: &str = "const0";
let pasted = paste!([<CONST 0>]);
assert_eq!(pasted, CONST0);
+
+ let pasted = paste!([<CONST '0'>]);
+ assert_eq!(pasted, CONST0);
+
+ let pasted = paste!([<CONST "0">]);
+ assert_eq!(pasted, CONST0);
+
+ let pasted = paste!([<CONST r"0">]);
+ assert_eq!(pasted, CONST0);
+
+ let pasted = paste!([<CONST '\u{30}'>]);
+ assert_eq!(pasted, CONST0);
+}
+
+#[test]
+fn test_literal_suffix() {
+ macro_rules! literal {
+ ($bit:tt) => {
+ paste!([<1_u $bit>])
+ };
+ }
+
+ assert_eq!(literal!(32), 1);
}
#[test]
@@ -235,3 +258,26 @@ mod test_local_setter {
assert_eq!(a.val, 42);
}
}
+
+// https://github.com/dtolnay/paste/issues/85
+#[test]
+fn test_top_level_none_delimiter() {
+ macro_rules! clone {
+ ($val:expr) => {
+ paste! {
+ $val.clone()
+ }
+ };
+ }
+
+ #[derive(Clone)]
+ struct A;
+
+ impl A {
+ fn consume_self(self) {
+ let _ = self;
+ }
+ }
+
+ clone!(&A).consume_self();
+}
diff --git a/tests/test_item.rs b/tests/test_item.rs
index 86c98a9..3821510 100644
--- a/tests/test_item.rs
+++ b/tests/test_item.rs
@@ -59,8 +59,8 @@ mod test_none_delimited_single_lifetime {
macro_rules! m {
($life:lifetime) => {
paste! {
- pub struct S;
- impl<$life> S {
+ pub struct S<$life>(&$life ());
+ impl<$life> S<$life> {
fn f() {}
}
}
diff --git a/tests/ui/invalid-ident.rs b/tests/ui/invalid-ident.rs
index d566e65..6a8cf3c 100644
--- a/tests/ui/invalid-ident.rs
+++ b/tests/ui/invalid-ident.rs
@@ -4,4 +4,12 @@ paste! {
fn [<0 f>]() {}
}
+paste! {
+ fn [<f '"'>]() {}
+}
+
+paste! {
+ fn [<f "'">]() {}
+}
+
fn main() {}
diff --git a/tests/ui/invalid-ident.stderr b/tests/ui/invalid-ident.stderr
index 8a233cb..28593fb 100644
--- a/tests/ui/invalid-ident.stderr
+++ b/tests/ui/invalid-ident.stderr
@@ -1,5 +1,21 @@
-error: `"0f"` is not a valid identifier
- --> tests/ui/invalid-ident.rs:4:8
+error: expected identifier, found `0f`
+ --> tests/ui/invalid-ident.rs:3:1
|
-4 | fn [<0 f>]() {}
- | ^^^^^^^
+3 | / paste! {
+4 | | fn [<0 f>]() {}
+5 | | }
+ | |_^ expected identifier
+ |
+ = note: this error originates in the macro `paste` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: `"f\""` is not a valid identifier
+ --> tests/ui/invalid-ident.rs:8:8
+ |
+8 | fn [<f '"'>]() {}
+ | ^^^^^^^^^
+
+error: `"f'"` is not a valid identifier
+ --> tests/ui/invalid-ident.rs:12:8
+ |
+12 | fn [<f "'">]() {}
+ | ^^^^^^^^^
diff --git a/tests/ui/unsupported-literal.rs b/tests/ui/unsupported-literal.rs
index 6538971..7a9c490 100644
--- a/tests/ui/unsupported-literal.rs
+++ b/tests/ui/unsupported-literal.rs
@@ -1,7 +1,21 @@
use paste::paste;
paste! {
- fn [<1e+100>]() {}
+ fn [<x 1e+100 z>]() {}
+}
+
+paste! {
+ // `xyz` is not correct. `xbyz` is certainly not correct. Maybe `x121z`
+ // would be justifiable but for now don't accept this.
+ fn [<x b'y' z>]() {}
+}
+
+paste! {
+ fn [<x b"y" z>]() {}
+}
+
+paste! {
+ fn [<x br"y" z>]() {}
}
fn main() {}
diff --git a/tests/ui/unsupported-literal.stderr b/tests/ui/unsupported-literal.stderr
index 842e2f2..a802b45 100644
--- a/tests/ui/unsupported-literal.stderr
+++ b/tests/ui/unsupported-literal.stderr
@@ -1,5 +1,23 @@
error: unsupported literal
- --> tests/ui/unsupported-literal.rs:4:10
+ --> tests/ui/unsupported-literal.rs:4:12
|
-4 | fn [<1e+100>]() {}
- | ^^^^^^
+4 | fn [<x 1e+100 z>]() {}
+ | ^^^^^^
+
+error: unsupported literal
+ --> tests/ui/unsupported-literal.rs:10:12
+ |
+10 | fn [<x b'y' z>]() {}
+ | ^^^^
+
+error: unsupported literal
+ --> tests/ui/unsupported-literal.rs:14:12
+ |
+14 | fn [<x b"y" z>]() {}
+ | ^^^^
+
+error: unsupported literal
+ --> tests/ui/unsupported-literal.rs:18:12
+ |
+18 | fn [<x br"y" z>]() {}
+ | ^^^^^