use mcai_license::{McaiWorkerLicense, OpenSourceLicense}; use serde_json::json; use std::str::FromStr; #[test] pub fn test_open_source_license_parsing() { assert!(OpenSourceLicense::from_str("MIT").is_ok()); assert!(OpenSourceLicense::from_str("Apache-2.0").is_ok()); assert_eq!( "Unable to parse license 'Licence IV'", OpenSourceLicense::from_str("Licence IV").unwrap_err() ); } #[test] pub fn test_open_source_license_new() { assert_eq!( OpenSourceLicense::from_str("MIT").unwrap(), OpenSourceLicense::new("MIT") ); assert_eq!( OpenSourceLicense::from_str("Apache-2.0").unwrap(), OpenSourceLicense::new("Apache-2.0") ); } #[test] #[should_panic( expected = "Invalid SPDX license identifier: \"Unable to parse license 'Licence IV'\"" )] pub fn test_open_source_license_new_invalid() { OpenSourceLicense::new("Licence IV"); } #[test] pub fn test_mcai_license_serialization() { assert_eq!( r#""Commercial""#, &serde_json::to_string(&McaiWorkerLicense::Commercial).unwrap() ); assert_eq!( r#""Private""#, &serde_json::to_string(&McaiWorkerLicense::Private).unwrap() ); assert_eq!( r#""MIT""#, &serde_json::to_string(&McaiWorkerLicense::OpenSource(OpenSourceLicense::new( "MIT" ))) .unwrap() ); } #[test] pub fn test_mcai_license_deserialization() { assert_eq!( McaiWorkerLicense::Commercial, serde_json::from_value(json!("Commercial")).unwrap() ); assert_eq!( McaiWorkerLicense::Private, serde_json::from_value(json!("Private")).unwrap() ); assert_eq!( McaiWorkerLicense::OpenSource(OpenSourceLicense::new("Apache-2.0")), serde_json::from_value(json!("Apache-2.0")).unwrap() ); assert_eq!( "Unable to parse license 'Licence IV'", serde_json::from_value::(json!("Licence IV")) .unwrap_err() .to_string() ); } #[test] pub fn test_mcai_license_parsing() { assert_eq!( McaiWorkerLicense::OpenSource(OpenSourceLicense::new("MIT")), McaiWorkerLicense::from_str("MIT").unwrap() ); assert_eq!( McaiWorkerLicense::OpenSource(OpenSourceLicense::new("Apache-2.0")), McaiWorkerLicense::from_str("Apache-2.0").unwrap() ); assert_eq!( McaiWorkerLicense::Commercial, McaiWorkerLicense::from_str("Commercial").unwrap() ); assert_eq!( McaiWorkerLicense::Private, McaiWorkerLicense::from_str("Private").unwrap() ); assert_eq!( "Unable to parse license 'Licence IV'", McaiWorkerLicense::from_str("Licence IV").unwrap_err() ); } #[test] pub fn test_mcai_license_new() { assert_eq!( McaiWorkerLicense::from_str("MIT").unwrap(), McaiWorkerLicense::new("MIT") ); assert_eq!( McaiWorkerLicense::from_str("Apache-2.0").unwrap(), McaiWorkerLicense::new("Apache-2.0") ); assert_eq!( McaiWorkerLicense::from_str("Commercial").unwrap(), McaiWorkerLicense::new("Commercial") ); assert_eq!( McaiWorkerLicense::from_str("Private").unwrap(), McaiWorkerLicense::new("Private") ); } #[test] #[should_panic(expected = "Invalid license identifier: \"Unable to parse license 'Licence IV'\"")] pub fn test_mcai_license_new_invalid() { McaiWorkerLicense::new("Licence IV"); }