diff options
Diffstat (limited to 'crates/mozart-spdx-licenses/src/lib.rs')
| -rw-r--r-- | crates/mozart-spdx-licenses/src/lib.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/mozart-spdx-licenses/src/lib.rs b/crates/mozart-spdx-licenses/src/lib.rs index a551988..0747703 100644 --- a/crates/mozart-spdx-licenses/src/lib.rs +++ b/crates/mozart-spdx-licenses/src/lib.rs @@ -12,6 +12,18 @@ pub struct LicenseInfo { pub deprecated: bool, } +impl LicenseInfo { + /// Canonical SPDX URL for this license. Mirrors Composer's + /// `SpdxLicenses::getLicenseByIdentifier()` which constructs the URL from + /// the identifier rather than storing it in the data file. + pub fn url(&self) -> String { + format!( + "https://spdx.org/licenses/{}.html#licenseText", + self.identifier + ) + } +} + /// Information about an SPDX license exception. #[derive(Debug, Clone)] pub struct ExceptionInfo { @@ -451,6 +463,21 @@ mod tests { } #[test] + fn license_url_uses_canonical_id() { + let db = spdx(); + let mit = db.get_license_by_identifier("MIT").unwrap(); + assert_eq!(mit.url(), "https://spdx.org/licenses/MIT.html#licenseText"); + + // Lookup is case-insensitive, but the URL uses the canonical casing + // from the database, mirroring Composer's `getLicenseByIdentifier`. + let mit_lower = db.get_license_by_identifier("mit").unwrap(); + assert_eq!( + mit_lower.url(), + "https://spdx.org/licenses/MIT.html#licenseText" + ); + } + + #[test] fn exception_lookup() { let db = spdx(); let exc = db |
