From da287b100ad7e0c5637a8fa40ea13193f38cd6da Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Mon, 4 Sep 2023 17:21:51 +0530 Subject: [PATCH] Test npm pre-release caret range handling Signed-off-by: Keshav Priyadarshi --- tests/test_version_range.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_version_range.py b/tests/test_version_range.py index 5449acb9..c92de0b7 100644 --- a/tests/test_version_range.py +++ b/tests/test_version_range.py @@ -216,6 +216,39 @@ def test_NpmVersionRange_from_native_with_compatible_with_version_operator(self) version_range = NpmVersionRange.from_native(npm_range) assert version_range == expected + def test_NpmVersionRange_from_native_with_prerelease_carate_range(self): + npm_range = "^1.2.3-beta.1" + expected = NpmVersionRange( + constraints=( + VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.3-beta.1")), + VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")), + ) + ) + version_range = NpmVersionRange.from_native(npm_range) + assert version_range == expected + + def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major(self): + npm_range = "^0.2.1-beta" + expected = NpmVersionRange( + constraints=( + VersionConstraint(comparator=">=", version=SemverVersion(string="0.2.1-beta")), + VersionConstraint(comparator="<", version=SemverVersion(string="0.3.0")), + ) + ) + version_range = NpmVersionRange.from_native(npm_range) + assert version_range == expected + + def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major_and_minor(self): + npm_range = "^0.0.2-beta" + expected = NpmVersionRange( + constraints=( + VersionConstraint(comparator=">=", version=SemverVersion(string="0.0.2-beta")), + VersionConstraint(comparator="<", version=SemverVersion(string="0.0.3")), + ) + ) + version_range = NpmVersionRange.from_native(npm_range) + assert version_range == expected + def test_NpmVersionRange_from_native_with_approximately_equal_to_operator(self): npm_range = "~3.8.2" expected = NpmVersionRange(