mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2025-02-18 14:40:40 +00:00
Update Meta::Path snapshots
This commit is contained in:
parent
d6c7db3edf
commit
28eec8e9c1
@ -12,7 +12,16 @@ use syn::{Attribute, Meta};
|
||||
fn test_meta_item_word() {
|
||||
let meta = test("#[foo]");
|
||||
|
||||
snapshot!(meta, @r###"Word("foo")"###);
|
||||
snapshot!(meta, @r###"
|
||||
⋮Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮})
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -21,7 +30,14 @@ fn test_meta_item_name_value() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
@ -33,7 +49,14 @@ fn test_meta_item_bool_value() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: Lit::Bool {
|
||||
⋮ value: true,
|
||||
⋮ },
|
||||
@ -44,7 +67,14 @@ fn test_meta_item_bool_value() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: Lit::Bool {
|
||||
⋮ value: false,
|
||||
⋮ },
|
||||
@ -58,7 +88,14 @@ fn test_meta_item_list_lit() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Literal(5),
|
||||
⋮ ],
|
||||
@ -72,9 +109,23 @@ fn test_meta_item_list_word() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Word("bar")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "bar",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ ],
|
||||
⋮}
|
||||
"###);
|
||||
@ -86,10 +137,24 @@ fn test_meta_item_list_name_value() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "bar",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "bar",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮ }),
|
||||
⋮ ],
|
||||
@ -103,10 +168,24 @@ fn test_meta_item_list_bool_value() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "bar",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "bar",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: Lit::Bool {
|
||||
⋮ value: true,
|
||||
⋮ },
|
||||
@ -122,23 +201,65 @@ fn test_meta_item_multiple() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Word("word")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮ }),
|
||||
⋮ Meta(Meta::List {
|
||||
⋮ ident: "list",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "list",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name2",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 6,
|
||||
⋮ }),
|
||||
⋮ ],
|
||||
⋮ }),
|
||||
⋮ Meta(Word("word2")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ ],
|
||||
⋮}
|
||||
"###);
|
||||
@ -150,7 +271,14 @@ fn test_bool_lit() {
|
||||
|
||||
snapshot!(meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Literal(Lit::Bool {
|
||||
⋮ value: true,
|
||||
|
@ -111,10 +111,31 @@ fn test_struct() {
|
||||
|
||||
snapshot!(input.attrs[0].parse_meta().unwrap(), @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "derive",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "derive",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Word("Debug")),
|
||||
⋮ Meta(Word("Clone")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "Debug",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "Clone",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ ],
|
||||
⋮}
|
||||
"###);
|
||||
@ -314,10 +335,24 @@ fn test_enum() {
|
||||
snapshot!(meta_items, @r###"
|
||||
⋮[
|
||||
⋮ Meta::NameValue {
|
||||
⋮ ident: "doc",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "doc",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: " See the std::result module documentation for details.",
|
||||
⋮ },
|
||||
⋮ Word("must_use"),
|
||||
⋮ Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "must_use",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ }),
|
||||
⋮]
|
||||
"###);
|
||||
}
|
||||
@ -437,7 +472,20 @@ fn test_attr_with_mod_style_path_with_self() {
|
||||
⋮}
|
||||
"###);
|
||||
|
||||
assert!(input.attrs[0].parse_meta().is_err());
|
||||
snapshot!(input.attrs[0].parse_meta().unwrap(), @r###"
|
||||
⋮Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "self",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮})
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -11,7 +11,16 @@ use syn::{Meta, MetaList, MetaNameValue, NestedMeta};
|
||||
fn test_parse_meta_item_word() {
|
||||
let input = "hello";
|
||||
|
||||
snapshot!(input as Meta, @r###"Word("hello")"###);
|
||||
snapshot!(input as Meta, @r###"
|
||||
⋮Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "hello",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮})
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -21,14 +30,28 @@ fn test_parse_meta_name_value() {
|
||||
|
||||
snapshot!(inner as MetaNameValue, @r###"
|
||||
⋮MetaNameValue {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
|
||||
snapshot!(meta as Meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
@ -43,14 +66,28 @@ fn test_parse_meta_name_value_with_keyword() {
|
||||
|
||||
snapshot!(inner as MetaNameValue, @r###"
|
||||
⋮MetaNameValue {
|
||||
⋮ ident: "static",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "static",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
|
||||
snapshot!(meta as Meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "static",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "static",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
@ -65,14 +102,28 @@ fn test_parse_meta_name_value_with_bool() {
|
||||
|
||||
snapshot!(inner as MetaNameValue, @r###"
|
||||
⋮MetaNameValue {
|
||||
⋮ ident: "true",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "true",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
|
||||
snapshot!(meta as Meta, @r###"
|
||||
⋮Meta::NameValue {
|
||||
⋮ ident: "true",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "true",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮}
|
||||
"###);
|
||||
@ -87,7 +138,14 @@ fn test_parse_meta_item_list_lit() {
|
||||
|
||||
snapshot!(inner as MetaList, @r###"
|
||||
⋮MetaList {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Literal(5),
|
||||
⋮ ],
|
||||
@ -96,7 +154,14 @@ fn test_parse_meta_item_list_lit() {
|
||||
|
||||
snapshot!(meta as Meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Literal(5),
|
||||
⋮ ],
|
||||
@ -113,46 +178,130 @@ fn test_parse_meta_item_multiple() {
|
||||
|
||||
snapshot!(inner as MetaList, @r###"
|
||||
⋮MetaList {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Word("word")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮ }),
|
||||
⋮ Meta(Meta::List {
|
||||
⋮ ident: "list",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "list",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name2",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 6,
|
||||
⋮ }),
|
||||
⋮ ],
|
||||
⋮ }),
|
||||
⋮ Meta(Word("word2")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ ],
|
||||
⋮}
|
||||
"###);
|
||||
|
||||
snapshot!(meta as Meta, @r###"
|
||||
⋮Meta::List {
|
||||
⋮ ident: "foo",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "foo",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Word("word")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 5,
|
||||
⋮ }),
|
||||
⋮ Meta(Meta::List {
|
||||
⋮ ident: "list",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "list",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name2",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 6,
|
||||
⋮ }),
|
||||
⋮ ],
|
||||
⋮ }),
|
||||
⋮ Meta(Word("word2")),
|
||||
⋮ Meta(Path(Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "word2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ })),
|
||||
⋮ ],
|
||||
⋮}
|
||||
"###);
|
||||
@ -168,10 +317,24 @@ fn test_parse_nested_meta() {
|
||||
let input = "list(name2 = 6)";
|
||||
snapshot!(input as NestedMeta, @r###"
|
||||
⋮Meta(Meta::List {
|
||||
⋮ ident: "list",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "list",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ nested: [
|
||||
⋮ Meta(Meta::NameValue {
|
||||
⋮ ident: "name2",
|
||||
⋮ path: Path {
|
||||
⋮ segments: [
|
||||
⋮ PathSegment {
|
||||
⋮ ident: "name2",
|
||||
⋮ arguments: None,
|
||||
⋮ },
|
||||
⋮ ],
|
||||
⋮ },
|
||||
⋮ lit: 6,
|
||||
⋮ }),
|
||||
⋮ ],
|
||||
|
Loading…
x
Reference in New Issue
Block a user