Play

Check-in [eb5381534d]
Login
Overview
Comment:Implement function to check compatibility between semver versions.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: eb5381534d5f5ed215983ec3bf6fcfba3fe63dae0a2d32d5435d68c51c66b7fb
User & Date: robin.hansen on 2021-02-21 10:51:16
Other Links: branch diff | manifest | tags
Context
2021-02-25
14:55
Refactor model of PackageLoader. check-in: 3485ad3ca9 user: robin.hansen tags: modules
2021-02-21
10:51
Implement function to check compatibility between semver versions. check-in: eb5381534d user: robin.hansen tags: modules
2021-02-19
16:29
PackageLoader now supports reading in all relevant play.json files. check-in: 1285a94244 user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Data/SemanticVersion.elm from [a5448c2ad1] to [b8b4cd3223].

1

2
3

4
5
6
7
8
9
10
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
42
43
44
45
46
47
48







































module Play.Data.SemanticVersion exposing

    ( ParseError(..)
    , SemanticVersion

    , fromString
    )


type SemanticVersion
    = SemanticVersion Int Int Int

................................................................................
    | LessThanMinimumVersion String


fromString : String -> Result ParseError SemanticVersion
fromString str =
    case String.split "." str of
        [ major, minor, patch ] ->
            toInt str major minor patch

        _ ->
            Err <| InvalidFormat str


toInt : String -> String -> String -> String -> Result ParseError SemanticVersion
toInt originalStr majorStr minorStr patchStr =
    let
        intVersions =
            [ majorStr, minorStr, patchStr ]
                |> List.filterMap String.toInt
    in
    case intVersions of
        [ major, minor, patch ] ->
................................................................................
                Err <| LessThanMinimumVersion originalStr

            else
                Ok <| SemanticVersion major minor patch

        _ ->
            Err <| ExpectedInteger originalStr








































>
|

>







 







|





|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
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
module Play.Data.SemanticVersion exposing
    ( Compatibility(..)
    , ParseError(..)
    , SemanticVersion
    , compatible
    , fromString
    )


type SemanticVersion
    = SemanticVersion Int Int Int

................................................................................
    | LessThanMinimumVersion String


fromString : String -> Result ParseError SemanticVersion
fromString str =
    case String.split "." str of
        [ major, minor, patch ] ->
            fromInts str major minor patch

        _ ->
            Err <| InvalidFormat str


fromInts : String -> String -> String -> String -> Result ParseError SemanticVersion
fromInts originalStr majorStr minorStr patchStr =
    let
        intVersions =
            [ majorStr, minorStr, patchStr ]
                |> List.filterMap String.toInt
    in
    case intVersions of
        [ major, minor, patch ] ->
................................................................................
                Err <| LessThanMinimumVersion originalStr

            else
                Ok <| SemanticVersion major minor patch

        _ ->
            Err <| ExpectedInteger originalStr


type Compatibility
    = Incompatible
    | LessThan
    | GreaterThanOrEqual


compatible : SemanticVersion -> SemanticVersion -> Compatibility
compatible (SemanticVersion lhsMajor lhsMinor lhsPatch) (SemanticVersion rhsMajor rhsMinor rhsPatch) =
    if lhsMajor /= rhsMajor then
        Incompatible

    else
        case compare lhsMinor rhsMinor of
            GT ->
                if lhsMajor == 0 then
                    Incompatible

                else
                    LessThan

            LT ->
                if lhsMajor == 0 then
                    Incompatible

                else
                    GreaterThanOrEqual

            EQ ->
                case compare lhsPatch rhsPatch of
                    GT ->
                        LessThan

                    EQ ->
                        GreaterThanOrEqual

                    LT ->
                        GreaterThanOrEqual

Modified tests/Test/Data/SemanticVersion.elm from [1c381630ef] to [831feac96b].

50
51
52
53
54
55
56














57


















        , test "Cannot contain negative versions" <|
            \_ ->
                PlayExpect.allEqual SemanticVersion.fromString
                    [ ( "-1.0.0", Err <| SemanticVersion.NegativeVersions "-1.0.0" )
                    , ( "1.-2.0", Err <| SemanticVersion.NegativeVersions "1.-2.0" )
                    , ( "1.2.-3", Err <| SemanticVersion.NegativeVersions "1.2.-3" )
                    ]














        ]

























>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
        , test "Cannot contain negative versions" <|
            \_ ->
                PlayExpect.allEqual SemanticVersion.fromString
                    [ ( "-1.0.0", Err <| SemanticVersion.NegativeVersions "-1.0.0" )
                    , ( "1.-2.0", Err <| SemanticVersion.NegativeVersions "1.-2.0" )
                    , ( "1.2.-3", Err <| SemanticVersion.NegativeVersions "1.2.-3" )
                    ]
        , describe "Compatibility" <|
            let
                helper ( lhs, rhs ) =
                    Result.map2 SemanticVersion.compatible (SemanticVersion.fromString lhs) (SemanticVersion.fromString rhs)
            in
            [ test "Same version, or greater version, returns GreaterThanOrEqual" <|
                \_ ->
                    PlayExpect.allEqual helper
                        [ ( ( "1.0.0", "1.0.0" ), Ok SemanticVersion.GreaterThanOrEqual )
                        , ( ( "0.2.1", "0.2.1" ), Ok SemanticVersion.GreaterThanOrEqual )
                        , ( ( "2.0.8", "2.0.8" ), Ok SemanticVersion.GreaterThanOrEqual )
                        , ( ( "1.0.0", "1.2.0" ), Ok SemanticVersion.GreaterThanOrEqual )
                        , ( ( "2.1.0", "2.1.1" ), Ok SemanticVersion.GreaterThanOrEqual )
                        , ( ( "1.2.3", "1.3.0" ), Ok SemanticVersion.GreaterThanOrEqual )
                        ]
            , test "Lesser version returns LessThan" <|
                \_ ->
                    PlayExpect.allEqual helper
                        [ ( ( "0.2.1", "0.2.0" ), Ok SemanticVersion.LessThan )
                        , ( ( "1.1.0", "1.0.5" ), Ok SemanticVersion.LessThan )
                        , ( ( "2.1.3", "2.1.1" ), Ok SemanticVersion.LessThan )
                        , ( ( "1.2.3", "1.2.2" ), Ok SemanticVersion.LessThan )
                        ]
            , test "Incompatible versions" <|
                \_ ->
                    PlayExpect.allEqual helper
                        [ ( ( "0.2.1", "0.3.0" ), Ok SemanticVersion.Incompatible )
                        , ( ( "1.0.0", "2.0.0" ), Ok SemanticVersion.Incompatible )
                        , ( ( "1.2.0", "2.2.0" ), Ok SemanticVersion.Incompatible )
                        , ( ( "0.0.1", "1.0.1" ), Ok SemanticVersion.Incompatible )
                        ]
            ]
        ]