about summary refs log tree commit diff
path: root/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-compareVersions.nix
blob: cce554b4494a49c001e5100d776eeb2542ccb3ba (plain) (blame)
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
let
  cmp = a: b:
    let
      ord1 = builtins.compareVersions a b;
      ord2 = builtins.compareVersions b a;
    in
      assert ord1 == -ord2; ord1;
in

[
  (cmp "1.2.3" "1.2.3")
  (cmp "1.2.2" "1.2.3")
  (cmp "1.2.3" "1.2.40")
  (cmp "1.2.3" ".1.2.3")
  (cmp "1.2.3" "1..2.3")
  (cmp "1.2.3" "1.2.3.")
  (cmp "1.2.3" "1.2")
  (cmp "1.2.3" "1.2.a")
  (cmp "1a.b" "1a.2")
  (cmp "1" "")
  (cmp "1.0" "1.0.0")
  (cmp "2.3" "2.3pre")
  (cmp "2.3" "2.3.0pre")
  (cmp "2.3pre" "2.3.0pre")
  (cmp "2.3" "2.3prepre")
  (cmp "2.3pre" "2.3prepre")
  (cmp "2.3prepre" "2.3prepre")
  # check that the plain word comparison (via Ord) behaves the same
  (cmp "foo" "bar")
  (cmp "FoO" "fOo")
  (cmp "foo" "fooo")
  (cmp "foopre" "foo")
  # Subset of test cases from eval-okay-versions.nix shipped by C++ Nix
  (cmp "1.0" "2.3")
  (cmp "2.1" "2.3")
  (cmp "2.3" "2.3")
  (cmp "2.5" "2.3")
  (cmp "3.1" "2.3")
  (cmp "2.3.1" "2.3")
  (cmp "2.3.1" "2.3a")
  (cmp "2.3pre1" "2.3")
  (cmp "2.3pre3" "2.3pre12")
  (cmp "2.3a" "2.3c")
  (cmp "2.3pre1" "2.3c")
  (cmp "2.3pre1" "2.3q")
]