Play

Check-in [8dca27fd4f]
Login
Overview
Comment:Factor out test helper functions.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: 8dca27fd4f35e465c617026f11ee5efa50204beb11da8bbc0233db34d570b1d3
User & Date: robin.hansen on 2021-02-12 12:56:53
Other Links: branch diff | manifest | tags
Context
2021-02-12
13:16
Implement conversion from String to SemanticVersion. check-in: d66b3a6dad user: robin.hansen tags: modules
12:56
Factor out test helper functions. check-in: 8dca27fd4f user: robin.hansen tags: modules
12:21
Implemented conversion from String to opaque PackageName type. check-in: b410ba3fed user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/Data/PackageName.elm from [244389ec31] to [bcb092c8ca].

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

import Expect
import Play.Data.PackageName as PackageName
import Test exposing (Test, describe, test)



suite : Test
suite =
    describe "PackageName"
        [ test "valid package names" <|
            \_ ->
                expectAllOk PackageName.fromString
                    [ "some/package"
                    , "play/std_lib"
                    , "number1/package123"
                    , "play_std/lib"
                    ]
        , test "Must contain exactly two parts, seperated by a single slash" <|
            \_ ->
                expectAllErr PackageName.fromString
                    [ "/"
                    , "one/"
                    , "/one"
                    , "one"
                    , "one/two/three"
                    ]
        , test "Both parts of a name must start with lower cased ascii character" <|
            \_ ->
                expectAllErr PackageName.fromString
                    [ "1pack/name"
                    , "_priv/pack"
                    , "#whaaat/events"
                    , "Some/package"
                    , "pack/1name"
                    , "priv/_pack"
                    , "whaaat/#events"
                    , "some/Package"
                    ]
        , test "Both parts of a name cannot contain upper case letters" <|
            \_ ->
                expectAllErr PackageName.fromString
                    [ "myPack/name"
                    , "mypackage/someName"
                    , "mypackage/some_Name"
                    ]
        , test "Both parts of a name cannot contain non ascii or digit letters" <|
            \_ ->
                expectAllErr PackageName.fromString
                    [ "my#pack/name"
                    , "mypackage/bills$"
                    ]
        ]


expectAllOk : (a -> Result err ok) -> List a -> Expect.Expectation
expectAllOk fn values =
    let
        expectationList =
            List.map (\val -> \f -> f val |> expectOk val) values

        expectOk original result =
            case result of
                Ok _ ->
                    Expect.pass

                Err _ ->
                    Expect.fail <| "Expected Ok for input " ++ Debug.toString original ++ ", was: " ++ Debug.toString result
    in
    Expect.all expectationList fn


expectAllErr : (a -> Result err ok) -> List a -> Expect.Expectation
expectAllErr fn values =
    let
        expectationList =
            List.map (\val -> \f -> f val |> expectErr val) values

        expectErr original result =
            case result of
                Ok _ ->
                    Expect.fail <| "Expected Err for input " ++ Debug.toString original ++ ", was: " ++ Debug.toString result

                Err _ ->
                    Expect.pass
    in
    Expect.all expectationList fn





>







|







|








|











|






|




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
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


































module Test.Data.PackageName exposing (suite)

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


suite : Test
suite =
    describe "PackageName"
        [ test "valid package names" <|
            \_ ->
                PlayExpect.allOk PackageName.fromString
                    [ "some/package"
                    , "play/std_lib"
                    , "number1/package123"
                    , "play_std/lib"
                    ]
        , test "Must contain exactly two parts, seperated by a single slash" <|
            \_ ->
                PlayExpect.allErr PackageName.fromString
                    [ "/"
                    , "one/"
                    , "/one"
                    , "one"
                    , "one/two/three"
                    ]
        , test "Both parts of a name must start with lower cased ascii character" <|
            \_ ->
                PlayExpect.allErr PackageName.fromString
                    [ "1pack/name"
                    , "_priv/pack"
                    , "#whaaat/events"
                    , "Some/package"
                    , "pack/1name"
                    , "priv/_pack"
                    , "whaaat/#events"
                    , "some/Package"
                    ]
        , test "Both parts of a name cannot contain upper case letters" <|
            \_ ->
                PlayExpect.allErr PackageName.fromString
                    [ "myPack/name"
                    , "mypackage/someName"
                    , "mypackage/some_Name"
                    ]
        , test "Both parts of a name cannot contain non ascii or digit letters" <|
            \_ ->
                PlayExpect.allErr PackageName.fromString
                    [ "my#pack/name"
                    , "mypackage/bills$"
                    ]
        ]


































Added tests/Test/PlayExpect.elm version [d38c5f4a89].

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
module Test.PlayExpect exposing
    ( allErr
    , allOk
    )

import Expect


allOk : (a -> Result err ok) -> List a -> Expect.Expectation
allOk fn values =
    let
        expectationList =
            List.map (\val -> \f -> f val |> expectOk val) values

        expectOk original result =
            case result of
                Ok _ ->
                    Expect.pass

                Err _ ->
                    Expect.fail <| "Expected Ok for input " ++ Debug.toString original ++ ", was: " ++ Debug.toString result
    in
    Expect.all expectationList fn


allErr : (a -> Result err ok) -> List a -> Expect.Expectation
allErr fn values =
    let
        expectationList =
            List.map (\val -> \f -> f val |> expectErr val) values

        expectErr original result =
            case result of
                Ok _ ->
                    Expect.fail <| "Expected Err for input " ++ Debug.toString original ++ ", was: " ++ Debug.toString result

                Err _ ->
                    Expect.pass
    in
    Expect.all expectationList fn