summaryrefslogtreecommitdiffstats
path: root/third_party/rust/darling/tests/unsupported_attributes.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/darling/tests/unsupported_attributes.rs
parentInitial commit. (diff)
downloadfirefox-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/darling/tests/unsupported_attributes.rs')
-rw-r--r--third_party/rust/darling/tests/unsupported_attributes.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/third_party/rust/darling/tests/unsupported_attributes.rs b/third_party/rust/darling/tests/unsupported_attributes.rs
new file mode 100644
index 0000000000..14edf2c858
--- /dev/null
+++ b/third_party/rust/darling/tests/unsupported_attributes.rs
@@ -0,0 +1,49 @@
+use darling::FromDeriveInput;
+use syn::{parse_quote, Ident, LitStr, Path};
+
+#[derive(Debug, FromDeriveInput)]
+#[darling(supports(struct_unit), attributes(bar))]
+pub struct Bar {
+ pub ident: Ident,
+ pub st: Path,
+ pub file: LitStr,
+}
+
+/// Per [#96](https://github.com/TedDriggs/darling/issues/96), make sure that an
+/// attribute which isn't a valid meta gets an error.
+#[test]
+fn non_meta_attribute_gets_own_error() {
+ let di = parse_quote! {
+ #[derive(Bar)]
+ #[bar(file = "motors/example_6.csv", st = RocketEngine)]
+ pub struct EstesC6;
+ };
+
+ let errors: darling::Error = Bar::from_derive_input(&di).unwrap_err().flatten();
+ // The number of errors here is 1 for the bad attribute + 2 for the missing fields
+ assert_eq!(3, errors.len());
+ // Make sure one of the errors propagates the syn error
+ assert!(errors
+ .into_iter()
+ .any(|e| e.to_string().contains("expected lit")));
+}
+
+/// Properties can be split across multiple attributes; this test ensures that one
+/// non-meta attribute does not interfere with the parsing of other, well-formed attributes.
+#[test]
+fn non_meta_attribute_does_not_block_others() {
+ let di = parse_quote! {
+ #[derive(Bar)]
+ #[bar(st = RocketEngine)]
+ #[bar(file = "motors/example_6.csv")]
+ pub struct EstesC6;
+ };
+
+ let errors: darling::Error = Bar::from_derive_input(&di).unwrap_err().flatten();
+ // The number of errors here is 1 for the bad attribute + 1 for the missing "st" field
+ assert_eq!(2, errors.len());
+ // Make sure one of the errors propagates the syn error
+ assert!(errors
+ .into_iter()
+ .any(|e| e.to_string().contains("expected lit")));
+}