meson/unittests/cargotests.py

62 lines
1.8 KiB
Python
Raw Normal View History

# 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)