Play

Check-in [ddeb331151]
Login
Overview
Comment:Implement conversion from String to ModuleName.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: ddeb331151d5cb0d055866e530e96f14575e8d397ba61f0dd2a26806ede3168c
User & Date: robin.hansen on 2021-02-13 10:20:56
Other Links: branch diff | manifest | tags
Context
2021-02-14
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
07:45
Implement conversion from String to PackagePath. check-in: a1c159f148 user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Data/ModuleName.elm from [95823ff653] to [701c19b7ec].

1





2
3
4
5













module Play.Data.ModuleName exposing (ModuleName)







type ModuleName
    = ModuleName String













|
>
>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Play.Data.ModuleName exposing
    ( ModuleName
    , fromString
    )

import Play.Data.PackageName as PackageName


type ModuleName
    = ModuleName String


fromString : String -> Result () ModuleName
fromString str =
    let
        parts =
            String.split "/" str
    in
    if List.any PackageName.invalidPart parts then
        Err ()

    else
        Ok <| ModuleName <| String.join "/" parts

Modified src/Play/Data/PackageName.elm from [0c8e8634cf] to [f7a2e868d7].

1
2
3

4
5
6
7
8
9
10
module Play.Data.PackageName exposing
    ( PackageName
    , fromString

    )


type PackageName
    = PackageName String String





>







1
2
3
4
5
6
7
8
9
10
11
module Play.Data.PackageName exposing
    ( PackageName
    , fromString
    , invalidPart
    )


type PackageName
    = PackageName String String


Added tests/Test/Data/ModuleName.elm version [e695b443b4].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
module Test.Data.ModuleName exposing (suite)

import Expect
import Fuzz
import Play.Data.ModuleName as ModuleName
import Play.Data.PackageName as PackageName
import Test exposing (Test, describe, fuzz, test)
import Test.PlayExpect as PlayExpect


suite : Test
suite =
    describe "ModuleName"
        [ fuzz Fuzz.string "Valid 2-part module names are also valid package names" <|
            \name ->
                let
                    combinedModuleName =
                        String.join "/" [ name, name ]
                in
                expectSameResult
                    (PackageName.fromString combinedModuleName)
                    (ModuleName.fromString combinedModuleName)
        , test "Module names can have only one part" <|
            \_ ->
                Expect.ok <| ModuleName.fromString "dict"
        , test "Module names can have many parts" <|
            \_ ->
                Expect.ok <| ModuleName.fromString "stdlib/dict/ordered"
        , test "The empty string is not a valid module name" <|
            \_ ->
                Expect.err <| ModuleName.fromString ""
        , test "Module names cannot start with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "/dict"
        , test "Module names cannot end with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "dict/"
        ]


expectSameResult : Result aErr aOk -> Result bErr bOk -> Expect.Expectation
expectSameResult left right =
    case ( left, right ) of
        ( Ok _, Ok _ ) ->
            Expect.pass

        ( Err _, Err _ ) ->
            Expect.pass

        _ ->
            Expect.fail <| "Different results: " ++ Debug.toString ( left, right )