#![cfg(all(feature = "v4", feature = "std"))]
use cvss::v4::Vector;
use std::{fs, str::FromStr};
fn run_tests_from_file(name: &str, test_serialization: bool) {
let content = fs::read_to_string(format!("tests/cvss-redhat/tests/{}", name)).unwrap();
for l in content.lines() {
let parts = l.split(" - ").collect::<Vec<&str>>();
let cvss = Vector::from_str(parts[0]).unwrap();
if test_serialization {
assert_eq!(cvss.to_string(), parts[0]);
}
assert!(cvss.score().value() >= 0.0);
assert!(cvss.score().value() <= 10.0);
let diff: f64 = cvss.score().value() - parts[1].parse::<f64>().unwrap();
assert!(diff.abs() < 0.0001);
}
}
#[test]
fn cvss_v4_base() {
run_tests_from_file("vectors_base4", true);
}
#[test]
fn cvss_v4_modified() {
run_tests_from_file("vectors_modified4", true);
}
#[test]
fn cvss_v4_supplemental() {
run_tests_from_file("vectors_supplemental4", true);
}
#[test]
fn cvss_v4_security() {
run_tests_from_file("vectors_security4", true);
}
#[test]
fn cvss_v4_threat() {
run_tests_from_file("vectors_threat4", true);
}
#[test]
fn cvss_v4_random() {
run_tests_from_file("vectors_random4", false);
}