1// SPDX-FileCopyrightText: 2020-2021 HH Partners
2//
3// SPDX-License-Identifier: MIT
4
5use serde::{Deserialize, Serialize};
6
7/// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/>
8#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq)]
9#[serde(rename_all = "camelCase")]
10pub struct OtherLicensingInformationDetected {
11 /// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/#61-license-identifier>
12 #[serde(rename = "licenseId")]
13 pub license_identifier: String,
14
15 /// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/#62-extracted-text>
16 pub extracted_text: String,
17
18 /// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/#63-license-name>
19 #[serde(rename = "name")]
20 #[serde(default = "default_noassertion")]
21 pub license_name: String,
22
23 /// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/#64-license-cross-reference>
24 #[serde(rename = "seeAlsos", skip_serializing_if = "Vec::is_empty", default)]
25 pub license_cross_reference: Vec<String>,
26
27 /// <https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/#65-license-comment>
28 #[serde(rename = "comment", skip_serializing_if = "Option::is_none", default)]
29 pub license_comment: Option<String>,
30}
31
32fn default_noassertion() -> String {
33 "NOASSERTION".into()
34}
35
36#[cfg(test)]
37mod test {
38 use std::fs::read_to_string;
39
40 use crate::models::SPDX;
41
42 #[test]
43 fn license_identifier() {
44 let spdx: SPDX = serde_json::from_str(
45 &read_to_string("tests/data/SPDXJSONExample-v2.2.spdx.json").unwrap(),
46 )
47 .unwrap();
48 assert_eq!(
49 spdx.other_licensing_information_detected[0].license_identifier,
50 "LicenseRef-Beerware-4.2".to_string()
51 );
52 }
53 #[test]
54 fn extracted_text() {
55 let spdx: SPDX = serde_json::from_str(
56 &read_to_string("tests/data/SPDXJSONExample-v2.2.spdx.json").unwrap(),
57 )
58 .unwrap();
59 assert_eq!(spdx.other_licensing_information_detected[0].extracted_text, "\"THE BEER-WARE LICENSE\" (Revision 42):\nphk@FreeBSD.ORG wrote this file. As long as you retain this notice you\ncan do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp </\nLicenseName: Beer-Ware License (Version 42)\nLicenseCrossReference: http://people.freebsd.org/~phk/\nLicenseComment: \nThe beerware license has a couple of other standard variants.");
60 }
61 #[test]
62 fn license_name() {
63 let spdx: SPDX = serde_json::from_str(
64 &read_to_string("tests/data/SPDXJSONExample-v2.2.spdx.json").unwrap(),
65 )
66 .unwrap();
67 assert_eq!(
68 spdx.other_licensing_information_detected[2].license_name,
69 "CyberNeko License".to_string()
70 );
71 }
72 #[test]
73 fn license_cross_reference() {
74 let spdx: SPDX = serde_json::from_str(
75 &read_to_string("tests/data/SPDXJSONExample-v2.2.spdx.json").unwrap(),
76 )
77 .unwrap();
78 assert_eq!(
79 spdx.other_licensing_information_detected[2].license_cross_reference,
80 vec![
81 "http://people.apache.org/~andyc/neko/LICENSE".to_string(),
82 "http://justasample.url.com".to_string()
83 ]
84 );
85 }
86 #[test]
87 fn license_comment() {
88 let spdx: SPDX = serde_json::from_str(
89 &read_to_string("tests/data/SPDXJSONExample-v2.2.spdx.json").unwrap(),
90 )
91 .unwrap();
92 assert_eq!(
93 spdx.other_licensing_information_detected[2].license_comment,
94 Some("This is tye CyperNeko License".to_string())
95 );
96 }
97}
98