1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
# Copyright © 2021-2023 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
from .utils.versions import Version
import pytest
cases = [
("1.0", "1.0", 0),
("1.0", "2.0", -1),
("2.0", "1.0", 1),
("2.0.1", "2.0.1", 0),
("2.0", "2.0.1", -1),
("2.0.1", "2.0", 1),
("2.0.1a", "2.0.1a", 0),
("2.0.1a", "2.0.1", 1),
("2.0.1", "2.0.1a", -1),
("5.5p1", "5.5p1", 0),
("5.5p1", "5.5p2", -1),
("5.5p2", "5.5p1", 1),
("5.5p10", "5.5p10", 0),
("5.5p1", "5.5p10", -1),
("5.5p10", "5.5p1", 1),
("10xyz", "10.1xyz", -1),
("10.1xyz", "10xyz", 1),
("xyz10", "xyz10", 0),
("xyz10", "xyz10.1", -1),
("xyz10.1", "xyz10", 1),
("xyz.4", "xyz.4", 0),
("xyz.4", "8", -1),
("8", "xyz.4", 1),
("xyz.4", "2", -1),
("2", "xyz.4", 1),
("5.5p2", "5.6p1", -1),
("5.6p1", "5.5p2", 1),
("5.6p1", "6.5p1", -1),
("6.5p1", "5.6p1", 1),
("6.0.rc1", "6.0", 1),
("6.0", "6.0.rc1", -1),
("10b2", "10a1", 1),
("10a2", "10b2", -1),
("1.0aa", "1.0aa", 0),
("1.0a", "1.0aa", -1),
("1.0aa", "1.0a", 1),
("10.0001", "10.0001", 0),
("10.0001", "10.1", 0),
("10.1", "10.0001", 0),
("10.0001", "10.0039", -1),
("10.0039", "10.0001", 1),
("4.999.9", "5.0", -1),
("5.0", "4.999.9", 1),
("20101121", "20101121", 0),
("20101121", "20101122", -1),
("20101122", "20101121", 1),
("2_0", "2_0", 0),
("2.0", "2_0", 0),
("2_0", "2.0", 0),
# Additional nastiness
("2_0.", "2_0", 0),
("2..0", "2_0__", 0),
("2_0", "__2.0", 0),
("2_1.", "2_0", +1),
("2..1", "2_0__", +1),
("2_1", "__2.0", +1),
("2_1.", "2_2", -1),
("2..1", "2_2__", -1),
("2_1", "__2.2", -1),
# https://bugzilla.redhat.com/178798
("a", "a", 0),
("a+", "a+", 0),
("a+", "a_", 0),
("a_", "a+", 0),
("+a", "+a", 0),
("+a", "_a", 0),
("_a", "+a", 0),
("+_", "+_", 0),
("_+", "+_", 0),
("_+", "_+", 0),
("+", "_", 0),
("_", "+", 0),
# Basic testcases for tilde sorting
("1.0~rc1", "1.0~rc1", 0),
("1.0~rc1", "1.0", -1),
("1.0", "1.0~rc1", 1),
("1.0~rc1", "1.0~rc2", -1),
("1.0~rc2", "1.0~rc1", 1),
("1.0~rc1~git123", "1.0~rc1~git123", 0),
("1.0~rc1~git123", "1.0~rc1", -1),
("1.0~rc1", "1.0~rc1~git123", 1),
("a", "a", 0),
("a~", "a", -1),
("a~~", "a", -1),
("a~~~", "a", -1),
("a~~~^", "a", -1),
("a^", "a", +1),
("a^", "a", +1),
("a^", "a^", 0),
("a^", "a^^", -1),
("a^b", "a^^", +1),
# Basic testcases for caret sorting
("1.0^", "1.0^", 0),
("1.0^", "1.0", 1),
("1.0", "1.0^", -1),
("1.0^git1", "1.0^git1", 0),
("1.0^git1", "1.0", 1),
("1.0", "1.0^git1", -1),
("1.0^git1", "1.0^git2", -1),
("1.0^git2", "1.0^git1", 1),
("1.0^git1", "1.01", -1),
("1.01", "1.0^git1", 1),
("1.0^20160101", "1.0^20160101", 0),
("1.0^20160101", "1.0.1", -1),
("1.0.1", "1.0^20160101", 1),
("1.0^20160101^git1", "1.0^20160101^git1", 0),
("1.0^20160102", "1.0^20160101^git1", 1),
("1.0^20160101^git1", "1.0^20160102", -1),
# Basic testcases for tilde and caret sorting
("1.0~rc1^git1", "1.0~rc1^git1", 0),
("1.0~rc1^git1", "1.0~rc1", 1),
("1.0~rc1", "1.0~rc1^git1", -1),
("1.0^git1~pre", "1.0^git1~pre", 0),
("1.0^git1", "1.0^git1~pre", 1),
("1.0^git1~pre", "1.0^git1", -1),
# Additional testing for zeroes
("0", "0", 0),
("0", "00", 0),
("0", "000", 0),
("00", "000", 0),
("000", "000", 0),
("00", "0", 0),
("000", "0", 0),
("0", "0.0", -1),
("0.0", "0", +1),
("0~", "0", -1),
("0^", "0", +1),
("0^", "0^", 0),
("0^", "0^~", 1),
]
@pytest.mark.parametrize("a,b,expected", cases)
def test_version_comparisons(a, b, expected):
assert Version(a)._cmp(b) == expected
@pytest.mark.parametrize("a,b", [c[:2] for c in cases if c[2] < 0])
def test_version_lt(a, b):
assert Version(a) < b
assert Version(a) < Version(b)
@pytest.mark.parametrize("a,b", [c[:2] for c in cases if c[2] > 0])
def test_version_gt(a, b):
assert Version(a) > b
assert Version(a) > Version(b)
@pytest.mark.parametrize("a,b", [c[:2] for c in cases if c[2] == 0])
def test_version_gt(a, b):
assert Version(a) == b
assert Version(a) == Version(b)
|