/* ==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- Dia-Semver Copyright (C) 2018-2022 Anonymous There are several releases over multiple years, they are listed as ranges, such as: "2018-2022". This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . ::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::-- */ use { core::{ ops::RangeBounds, str::FromStr, }, dia_semver::{Range, Result, Semver}, }; #[test] fn ranges() -> Result<()> { // Single semver { let semver = Semver::new(0, 1, 2); let range = Range::from(&semver); assert!(range.contains(&semver)); for (s, expected) in &[ ("0.1.2", true), ("0.1.2-apha", false), ("0.1.1", false), ("0.1.3", false), ("0.1.3+beta", false), ] { assert_eq!(range.contains(&Semver::from_str(s)?), *expected); } } // Empty ranges assert_eq!(Range::from(Semver::new(0, 0, 0)).is_empty(), false); for s in &[ "[0.1.2, 0.1.1]", "[0.1.2, 0.1.1)", "[0.1.2, 0.1.2-alpha]", "[0.1.2, 0.1.2-alpha)", "(0.1.2, 0.1.2)", "(0.1.2, 0.1.2]", "(0.1.2, 0.1.2+beta)", "(0.1.2, 0.1.2-beta)", "(0.1.2, 0.1.2-beta]", ] { let range = Range::from_str(s)?; assert!(range.is_empty()); assert_eq!(Range::from_str(&range.to_string())?, range); } // Inclusive/exclusive for (range, semver, expected) in &[ ("[0.1.2, 0.1.2]", "0.1.2", true), ("[0.1.2, 0.1.2]", "0.1.2+beta", true), ("[0.1.2, 0.1.2+beta]", "0.1.2+some", true), ("[0.1.2, 0.1.2]", "0.1.2-alpha", false), ("[0.1.2, 0.1.2+some]", "0.1.2-alpha", false), ("[0.1.2, 0.1.3-alpha)", "0.1.2-alpha", false), ("[0.1.2, 0.1.3-alpha)", "0.1.2+beta", true), ("(0.1.2, 0.1.3-alpha)", "0.1.2+beta", false), ("(0.1.2, 0.1.3-beta)", "0.1.3-alpha", true), ] { let range = Range::from_str(range)?; assert_eq!(range.contains(&Semver::from_str(semver)?), *expected); assert_eq!(Range::from_str(&range.to_string())?, range); } Ok(()) }