Skip to content

Commit 3d76b3b

Browse files
committed
models::version: Add tests for validate_license_expr()
1 parent 1aefac3 commit 3d76b3b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/models/version.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn validate_license_expr(s: &str) -> AppResult<()> {
200200

201201
#[cfg(test)]
202202
mod tests {
203-
use super::TopVersions;
203+
use super::{validate_license_expr, TopVersions};
204204
use chrono::NaiveDateTime;
205205

206206
#[track_caller]
@@ -270,4 +270,20 @@ mod tests {
270270
}
271271
);
272272
}
273+
274+
#[test]
275+
fn licenses() {
276+
assert_ok!(validate_license_expr("MIT"));
277+
assert_ok!(validate_license_expr("MIT OR Apache-2.0"));
278+
assert_ok!(validate_license_expr("MIT/Apache-2.0"));
279+
assert_ok!(validate_license_expr("MIT AND Apache-2.0"));
280+
281+
let error = assert_err!(validate_license_expr("apache 2.0"));
282+
let error = format!("{}", error);
283+
assert!(error.starts_with("unknown license or other term: apache; see http"));
284+
285+
let error = assert_err!(validate_license_expr("MIT OR (Apache-2.0 AND MIT)"));
286+
let error = format!("{}", error);
287+
assert!(error.starts_with("unknown license or other term: (Apache-2.0; see http"));
288+
}
273289
}

0 commit comments

Comments
 (0)