/* ==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- 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::str::FromStr, std::collections::BTreeSet, dia_semver::Semver, }; #[test] fn ordering() { assert_eq!(Semver::from_str("1.0.0").unwrap(), Semver::from_str("1.0.0").unwrap()); assert!(Semver::from_str("1.0.0").unwrap() < Semver::from_str("1.0.1").unwrap()); assert!(Semver::from_str("1.1.0").unwrap() > Semver::from_str("1.0.1").unwrap()); assert_eq!(Semver::from_str("2.0.0-abc").unwrap(), Semver::from_str("2.0.0-abc").unwrap()); assert!(Semver::from_str("2.0.0-abc").unwrap() < Semver::from_str("2.0.0-xyz").unwrap()); assert_eq!(Semver::from_str("3.0-abc+2313").unwrap(), Semver::from_str("3.0.0-abc").unwrap()); assert_eq!(Semver::from_str("3.1.0-abc+2313").unwrap(), Semver::from_str("3.1-abc+xyz-123").unwrap()); assert_eq!(Semver::from_str("4-abc.123").unwrap(), Semver::from_str("4-abc.123").unwrap()); assert!(Semver::from_str("4-abc.123").unwrap() > Semver::from_str("4-123.abc").unwrap()); assert!(Semver::from_str("4-123").unwrap() < Semver::from_str("4-123.abc").unwrap()); assert!(Semver::from_str("5-123").unwrap() < Semver::from_str("5-321").unwrap()); assert!(Semver::from_str("5-123.abc").unwrap() < Semver::from_str("5-321").unwrap()); assert!(Semver::from_str("5-123").unwrap() < Semver::from_str("5-321.xyz").unwrap()); assert!(Semver::from_str("6").unwrap() > Semver::from_str("6-ABC").unwrap()); assert_eq!(Semver::from_str("6").unwrap(), Semver::from_str("6+ABC").unwrap()); assert_eq!(Semver::from_str("6+XYZ").unwrap(), Semver::from_str("6+ABC").unwrap()); // Comparing pre-releases assert!(Semver::from_str("7.0.0-123").unwrap() > Semver::from_str("7.0.0-9").unwrap()); assert!(Semver::from_str("7.0.0-123").unwrap() > Semver::from_str("7.0.0-99").unwrap()); assert!(Semver::from_str("7.0.0-123").unwrap() < Semver::from_str("7.0.0-321").unwrap()); assert!(Semver::from_str("7.0.0-123").unwrap() < Semver::from_str("7.0.0-999").unwrap()); assert_eq!(Semver::from_str("7.0.0-123456").unwrap(), Semver::from_str("7.0.0-123456").unwrap()); assert!(Semver::from_str("1.0.0-alpha").unwrap() < Semver::from_str("1.0.0-alpha.1").unwrap()); assert!(Semver::from_str("1.0.0-alpha.1").unwrap() < Semver::from_str("1.0.0-alpha.beta").unwrap()); assert!(Semver::from_str("1.0.0-alpha.beta").unwrap() < Semver::from_str("1.0.0-beta").unwrap()); assert!(Semver::from_str("1.0.0-beta").unwrap() < Semver::from_str("1.0.0-beta.2").unwrap()); assert!(Semver::from_str("1.0.0-beta.2").unwrap() < Semver::from_str("1.0.0-beta.11").unwrap()); assert!(Semver::from_str("1.0.0-beta.11").unwrap() < Semver::from_str("1.0.0-rc.1").unwrap()); assert!(Semver::from_str("1.0.0-rc.1").unwrap() < Semver::from_str("1.0.0").unwrap()); let mut set = BTreeSet::new(); set.insert(Semver::from_str("1.0.0+a.b.c").unwrap()); set.insert(Semver::from_str("1.0.0").unwrap()); assert_eq!(set.len(), 1); }