Play

Check-in [28d1fb8fd8]
Login
Overview
Comment:On second thought, better be strict with semantic versioning.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: 28d1fb8fd8ae0539b15c164f0b8720b576007e23b8737cca1cf226441264f940
User & Date: robin.hansen on 2021-02-14 10:43:07
Other Links: branch diff | manifest | tags
Context
2021-02-14
10:59
SemanticVersion now returns descriptive error messages. check-in: 635fab0eeb user: robin.hansen tags: modules
10:43
On second thought, better be strict with semantic versioning. check-in: 28d1fb8fd8 user: robin.hansen tags: modules
2021-02-13
10:20
Implement conversion from String to ModuleName. check-in: ddeb331151 user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Data/SemanticVersion.elm from [8d8ba8498e] to [92b365e1e7].

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
type SemanticVersion
    = SemanticVersion Int Int Int


fromString : String -> Result () SemanticVersion
fromString str =
    case String.split "." str of
        [ major ] ->
            toInt major Nothing Nothing

        [ major, minor ] ->
            toInt major (Just minor) Nothing

        [ major, minor, patch ] ->
            toInt major (Just minor) (Just patch)

        _ ->
            Err ()


toInt : String -> Maybe String -> Maybe String -> Result () SemanticVersion
toInt majorStr maybeMinorStr maybePatchStr =
    let
        minorStr =
            Maybe.withDefault "0" maybeMinorStr

        patchStr =
            Maybe.withDefault "0" maybePatchStr

        intVersions =
            [ majorStr, minorStr, patchStr ]
                |> List.filterMap String.toInt
    in
    case intVersions of
        [ major, minor, patch ] ->
            if major < 0 || minor < 0 || patch < 0 then







<
<
<
<
<
<

|





|
|

<
<
<
<
<
<







7
8
9
10
11
12
13






14
15
16
17
18
19
20
21
22
23






24
25
26
27
28
29
30
type SemanticVersion
    = SemanticVersion Int Int Int


fromString : String -> Result () SemanticVersion
fromString str =
    case String.split "." str of






        [ major, minor, patch ] ->
            toInt major minor patch

        _ ->
            Err ()


toInt : String -> String -> String -> Result () SemanticVersion
toInt majorStr minorStr patchStr =
    let






        intVersions =
            [ majorStr, minorStr, patchStr ]
                |> List.filterMap String.toInt
    in
    case intVersions of
        [ major, minor, patch ] ->
            if major < 0 || minor < 0 || patch < 0 then

Modified tests/Test/Data/SemanticVersion.elm from [8794572d0d] to [7aa88bfaa0].

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

suite : Test
suite =
    describe "SemanticVersion"
        [ test "Valid versions" <|
            \_ ->
                PlayExpect.allOk SemanticVersion.fromString
                    [ "1"
                    , "1.2"
                    , "1.2.3"
                    , "10.100.1000"
                    , "0.0.1"
                    , "0.1.0"
                    ]
        , test "Cannot contain more than three parts" <|
            \_ ->
                SemanticVersion.fromString "1.2.3.4"
                    |> Expect.err






        , test "Cannot be empty string" <|
            \_ ->
                SemanticVersion.fromString ""
                    |> Expect.err
        , test "Must be numbers" <|
            \_ ->
                PlayExpect.allErr SemanticVersion.fromString
                    [ "A"
                    , "*"
                    , "~"
                    , "1.0.x"

                    , "~1.0.0"
                    , "1.0.0-alpha1"
                    , "alpha.1"
                    ]
        , test "Minimum version is 0.0.1" <|
            \_ ->
                SemanticVersion.fromString "0.0.0"
                    |> Expect.err
        , test "Cannot contain negative versions" <|
            \_ ->
                PlayExpect.allErr SemanticVersion.fromString
                    [ "-1"
                    , "-1.2"
                    , "1.-2.0"

                    ]
        ]







<
<
|








>
>
>
>
>
>











>











|
<

>


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

suite : Test
suite =
    describe "SemanticVersion"
        [ test "Valid versions" <|
            \_ ->
                PlayExpect.allOk SemanticVersion.fromString


                    [ "1.2.3"
                    , "10.100.1000"
                    , "0.0.1"
                    , "0.1.0"
                    ]
        , test "Cannot contain more than three parts" <|
            \_ ->
                SemanticVersion.fromString "1.2.3.4"
                    |> Expect.err
        , test "Cannot contain less than three parts" <|
            \_ ->
                PlayExpect.allErr SemanticVersion.fromString
                    [ "1"
                    , "1.2"
                    ]
        , test "Cannot be empty string" <|
            \_ ->
                SemanticVersion.fromString ""
                    |> Expect.err
        , test "Must be numbers" <|
            \_ ->
                PlayExpect.allErr SemanticVersion.fromString
                    [ "A"
                    , "*"
                    , "~"
                    , "1.0.x"
                    , "1.0.~"
                    , "~1.0.0"
                    , "1.0.0-alpha1"
                    , "alpha.1"
                    ]
        , test "Minimum version is 0.0.1" <|
            \_ ->
                SemanticVersion.fromString "0.0.0"
                    |> Expect.err
        , test "Cannot contain negative versions" <|
            \_ ->
                PlayExpect.allErr SemanticVersion.fromString
                    [ "-1.0.0"

                    , "1.-2.0"
                    , "1.2.-1"
                    ]
        ]