protected static PackageMeta?ParsePackageMeta(TomlTable tomlData) { if (!tomlData.HasKey("package")) { return(null); } var packageMeta = tomlData["package"]; // TODO: Add warnings on missing values var result = new PackageMeta() { Namespace = TomlUtils.SafegetString(packageMeta, "namespace"), Name = TomlUtils.SafegetString(packageMeta, "name"), VersionNumber = TomlUtils.SafegetString(packageMeta, "versionNumber"), Description = TomlUtils.SafegetString(packageMeta, "description"), WebsiteUrl = TomlUtils.SafegetString(packageMeta, "websiteUrl"), ContainsNsfwContent = TomlUtils.SafegetBool(packageMeta, "containsNsfwContent"), Dependencies = new() }; if (packageMeta.HasKey("dependencies")) { var packageDependencies = packageMeta["dependencies"]; foreach (var packageName in packageDependencies.Keys) { // TODO: Validate both are strings if needed? result.Dependencies[packageName] = packageDependencies[packageName]; } } return(result); }
public void SafegetBool_WhenValueIsBool_ReturnsValue(string input, bool expected) { var table = CreateTomlTable(input); var actual = TomlUtils.SafegetBool(table, _key); Assert.Equal(expected, actual); }
public void SafegetBool_WhenKeyIsNotFound_ReturnsNull() { var table = CreateTomlTable(""); var actual = TomlUtils.SafegetBool(table, _key); Assert.Null(actual); }
public void SafegetBool_WhenValueIsNotBool_ReturnsNull(string input) { var table = CreateTomlTable(input); var actual = TomlUtils.SafegetBool(table, _key); Assert.Null(actual); }