fn valid()

in guppy/src/graph/summaries/package_set.rs [796:927]


    fn valid() {
        let mut valids = vec![];
        valids.push(("", PackageSetSummary::default()));

        let mut summary_ids = BTreeSet::new();
        summary_ids.insert(SummaryId {
            name: "x".to_owned(),
            version: Version::parse("1.0.0").expect("version 1.0.0 parsed"),
            source: SummarySource::CratesIo,
        });
        valids.push((
            r#"[[ids]]
        name = "x"
        version = "1.0.0"
        crates-io = true
        "#,
            PackageSetSummary {
                summary_ids,
                ..PackageSetSummary::default()
            },
        ));

        valids.push((
            r#"#
            workspace-members = []"#,
            PackageSetSummary::default(),
        ));

        let mut workspace_members = BTreeSet::new();
        workspace_members.insert("abc".to_owned());
        valids.push((
            r#"
            workspace-members = ["abc"]"#,
            PackageSetSummary {
                workspace_members,
                ..PackageSetSummary::default()
            },
        ));

        let mut third_party = vec![];
        third_party.push(ThirdPartySummary {
            name: "foo".to_owned(),
            version: VersionReq::default(),
            source: ThirdPartySource::Registry(None),
        });

        valids.push((
            r#"
            third-party = [ { name = "foo" } ]"#,
            PackageSetSummary {
                third_party,
                ..PackageSetSummary::default()
            },
        ));

        let mut third_party = vec![];
        third_party.push(ThirdPartySummary {
            name: "foo".to_owned(),
            version: VersionReq::default(),
            source: ThirdPartySource::Git {
                repo: "git-repo".to_owned(),
                req: GitReqSummary::Default,
            },
        });
        third_party.push(ThirdPartySummary {
            name: "foo".to_owned(),
            version: VersionReq::parse(">2.0").expect("version >2.0 parsed correctly"),
            source: ThirdPartySource::Registry(Some("foo".to_owned())),
        });
        third_party.push(ThirdPartySummary {
            name: "bar".to_owned(),
            version: VersionReq::default(),
            source: ThirdPartySource::Git {
                repo: "git-repo".to_owned(),
                req: GitReqSummary::Branch("x".to_owned()),
            },
        });
        third_party.push(ThirdPartySummary {
            name: "bar".to_owned(),
            version: VersionReq::default(),
            source: ThirdPartySource::Git {
                repo: "git-repo".to_owned(),
                req: GitReqSummary::Tag("y".to_owned()),
            },
        });
        third_party.push(ThirdPartySummary {
            name: "baz".to_owned(),
            version: VersionReq::parse("4.1").expect("version 4.1 parsed correctly"),
            source: ThirdPartySource::Git {
                repo: "git-repo".to_owned(),
                req: GitReqSummary::Rev("z".to_owned()),
            },
        });
        third_party.push(ThirdPartySummary {
            name: "baz".to_owned(),
            version: VersionReq::default(),
            source: ThirdPartySource::Url("url".to_owned()),
        });
        valids.push((
            r#"
            third-party = [
                { name = "foo", git = "git-repo" },
                { name = "foo", registry = "foo", version = ">2.0" },
                { name = "bar", git = "git-repo", branch = "x" },
                { name = "bar", git = "git-repo", tag = "y" },
                { name = "baz", git = "git-repo", rev = "z", version = "4.1" },
                { name = "baz", version = "*", url = "url" },
        ]
        "#,
            PackageSetSummary {
                third_party,
                ..PackageSetSummary::default()
            },
        ));

        for (input, expected) in valids {
            let formatted_input = format_input(input);
            let actual = toml::de::from_str(input).unwrap_or_else(|err| {
                panic!("{}\ndeserialization error: {}", formatted_input, err)
            });
            assert_eq!(expected, actual, "{}", formatted_input);

            let serialized = toml::ser::to_string(&actual)
                .unwrap_or_else(|err| panic!("{}\nserialization error: {}", formatted_input, err));

            // Check that the serialized output matches by parsing it again.
            let actual2 = toml::de::from_str(&serialized).unwrap_or_else(|err| {
                panic!("{}\ndeserialization error try 2: {}", formatted_input, err)
            });
            assert_eq!(actual, actual2, "{}", formatted_input);
        }
    }