summaryrefslogtreecommitdiffstats
path: root/rust/vendor/syn-0.15.44/tests/test_attribute.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
commita0aa2307322cd47bbf416810ac0292925e03be87 (patch)
tree37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/syn-0.15.44/tests/test_attribute.rs
parentInitial commit. (diff)
downloadsuricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz
suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/syn-0.15.44/tests/test_attribute.rs')
-rw-r--r--rust/vendor/syn-0.15.44/tests/test_attribute.rs279
1 files changed, 279 insertions, 0 deletions
diff --git a/rust/vendor/syn-0.15.44/tests/test_attribute.rs b/rust/vendor/syn-0.15.44/tests/test_attribute.rs
new file mode 100644
index 0000000..2a7e106
--- /dev/null
+++ b/rust/vendor/syn-0.15.44/tests/test_attribute.rs
@@ -0,0 +1,279 @@
+extern crate syn;
+
+mod features;
+
+#[macro_use]
+mod macros;
+
+use syn::parse::Parser;
+use syn::{Attribute, Meta};
+
+#[test]
+fn test_meta_item_word() {
+ let (interpret, parse) = test("#[foo]");
+
+ snapshot!(interpret, @r###"Word("foo")"###);
+
+ snapshot!(parse, @r###"Word("foo")"###);
+}
+
+#[test]
+fn test_meta_item_name_value() {
+ let (interpret, parse) = test("#[foo = 5]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: 5,
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: 5,
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_bool_value() {
+ let (interpret, parse) = test("#[foo = true]");;
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: true,
+ ⋮ },
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: true,
+ ⋮ },
+ ⋮}
+ "###);
+
+ let (interpret, parse) = test("#[foo = false]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: false,
+ ⋮ },
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::NameValue {
+ ⋮ ident: "foo",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: false,
+ ⋮ },
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_list_lit() {
+ let (interpret, parse) = test("#[foo(5)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Literal(5),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Literal(5),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_list_word() {
+ let (interpret, parse) = test("#[foo(bar)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Word("bar")),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Word("bar")),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_list_name_value() {
+ let (interpret, parse) = test("#[foo(bar = 5)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "bar",
+ ⋮ lit: 5,
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "bar",
+ ⋮ lit: 5,
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_list_bool_value() {
+ let (interpret, parse) = test("#[foo(bar = true)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "bar",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: true,
+ ⋮ },
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "bar",
+ ⋮ lit: Lit::Bool {
+ ⋮ value: true,
+ ⋮ },
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_meta_item_multiple() {
+ let (interpret, parse) = test("#[foo(word, name = 5, list(name2 = 6), word2)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Word("word")),
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "name",
+ ⋮ lit: 5,
+ ⋮ }),
+ ⋮ Meta(Meta::List {
+ ⋮ ident: "list",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "name2",
+ ⋮ lit: 6,
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ Meta(Word("word2")),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Meta(Word("word")),
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "name",
+ ⋮ lit: 5,
+ ⋮ }),
+ ⋮ Meta(Meta::List {
+ ⋮ ident: "list",
+ ⋮ nested: [
+ ⋮ Meta(Meta::NameValue {
+ ⋮ ident: "name2",
+ ⋮ lit: 6,
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ Meta(Word("word2")),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+#[test]
+fn test_bool_lit() {
+ let (interpret, parse) = test("#[foo(true)]");
+
+ snapshot!(interpret, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Literal(Lit::Bool {
+ ⋮ value: true,
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+
+ snapshot!(parse, @r###"
+ ⋮Meta::List {
+ ⋮ ident: "foo",
+ ⋮ nested: [
+ ⋮ Literal(Lit::Bool {
+ ⋮ value: true,
+ ⋮ }),
+ ⋮ ],
+ ⋮}
+ "###);
+}
+
+fn test(input: &str) -> (Meta, Meta) {
+ let attrs = Attribute::parse_outer.parse_str(input).unwrap();
+
+ assert_eq!(attrs.len(), 1);
+ let attr = attrs.into_iter().next().unwrap();
+
+ let interpret = attr.interpret_meta().unwrap();
+ let parse = attr.parse_meta().unwrap();
+ assert_eq!(interpret, parse);
+
+ (interpret, parse)
+}