summaryrefslogtreecommitdiff
path: root/unittests/cargotests.py
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/cargotests.py')
-rw-r--r--unittests/cargotests.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/unittests/cargotests.py b/unittests/cargotests.py
new file mode 100644
index 000000000..884052b39
--- /dev/null
+++ b/unittests/cargotests.py
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: Apache-2.0
+# Copyright © 2022-2023 Intel Corporation
+
+from __future__ import annotations
+import unittest
+import typing as T
+
+from mesonbuild.cargo.version import convert
+
+
+class CargoVersionTest(unittest.TestCase):
+
+ def test_cargo_to_meson(self) -> None:
+ cases: T.List[T.Tuple[str, T.List[str]]] = [
+ # Basic requirements
+ ('>= 1', ['>= 1']),
+ ('> 1', ['> 1']),
+ ('= 1', ['= 1']),
+ ('< 1', ['< 1']),
+ ('<= 1', ['<= 1']),
+
+ # tilde tests
+ ('~1', ['>= 1', '< 2']),
+ ('~1.1', ['>= 1.1', '< 1.2']),
+ ('~1.1.2', ['>= 1.1.2', '< 1.2.0']),
+
+ # Wildcards
+ ('*', []),
+ ('1.*', ['>= 1', '< 2']),
+ ('2.3.*', ['>= 2.3', '< 2.4']),
+
+ # Unqualified
+ ('2', ['>= 2', '< 3']),
+ ('2.4', ['>= 2.4', '< 3']),
+ ('2.4.5', ['>= 2.4.5', '< 3']),
+ ('0.0.0', ['< 1']),
+ ('0.0', ['< 1']),
+ ('0', ['< 1']),
+ ('0.0.5', ['>= 0.0.5', '< 0.0.6']),
+ ('0.5.0', ['>= 0.5', '< 0.6']),
+ ('0.5', ['>= 0.5', '< 0.6']),
+
+ # Caret (Which is the same as unqualified)
+ ('^2', ['>= 2', '< 3']),
+ ('^2.4', ['>= 2.4', '< 3']),
+ ('^2.4.5', ['>= 2.4.5', '< 3']),
+ ('^0.0.0', ['< 1']),
+ ('^0.0', ['< 1']),
+ ('^0', ['< 1']),
+ ('^0.0.5', ['>= 0.0.5', '< 0.0.6']),
+ ('^0.5.0', ['>= 0.5', '< 0.6']),
+ ('^0.5', ['>= 0.5', '< 0.6']),
+
+ # Multiple requirements
+ ('>= 1.2.3, < 1.4.7', ['>= 1.2.3', '< 1.4.7']),
+ ]
+
+ for (data, expected) in cases:
+ with self.subTest():
+ self.assertListEqual(convert(data), expected)
+