Play

Check-in [12f2f38909]
Login
Overview
Comment:Add unit test to make sure defining functions without bodies is legal.
Timelines: family | ancestors | descendants | both | alpha2-syntax-changes
Files: files | file ages | folders
SHA3-256: 12f2f38909c273dc885b420340d1f5591520566a4fd23a5c62e6482696441123
User & Date: robin.hansen on 2021-01-24 07:19:06
Other Links: branch diff | manifest | tags
Context
2021-01-24
07:22
Make syntax changes based on language proposal [49d490f836]. Fixes tickets [05dc3c652b], [2ed5dbbb6d... check-in: 5de766c3d5 user: robin.hansen tags: trunk
07:19
Add unit test to make sure defining functions without bodies is legal. Closed-Leaf check-in: 12f2f38909 user: robin.hansen tags: alpha2-syntax-changes
07:12
When defining multiwords, : now replaces when:, else: replaces :. check-in: 1b2a7e4296 user: robin.hansen tags: alpha2-syntax-changes
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/Parser.elm from [d53c1bfa79] to [a3937d228f].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
...
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
...
745
746
747
748
749
750
751






752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
import Dict.Extra as Dict
import Expect
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (SourceLocation, SourceLocationRange, emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST exposing (..)
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (addFunctionsForStructs, compile, compileRetainLocations)


suite : Test
suite =
    describe "Parser"
        [ test "Sample program" <|
            \_ ->
................................................................................
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
            ]
        , test "Support code comments" <|
            \_ ->
                let
                    expectCompiles code =
                        case compile code of
                            Err _ ->
                                Expect.fail "Did not expect compilation to fail."

                            Ok _ ->
                                Expect.pass
                in
                expectCompiles
                    """
                    # Increments the passed in value by one
                    def: inc
                    type: # as you'd expect
                      Int -- Int
                    : # again, pretty basic
................................................................................
                    type: Int -- Int
                    : 1
                      # + wouldnt work here
                      -

                    # And thats it!
                     # wonder what else we should do...






                    """
        , test "Correct line information" <|
            \_ ->
                let
                    source =
                        """
                       defunion: Bool
                       : True
                       : False

                       defstruct: True
                       defstruct: False

                       defmulti: from-int
                       type: Int -- Int
                       : Int( value 0 )
                         False
                       : Int
                         True

                       def: equal
                       : - from-int not

                       defmulti: not
                       : True
                         False
                       else: True
                       """

                    -- The ending source location for most definitions now ends where the next definition beings
                    -- This is not what we want (it includes too much white space), but it'll do for now.
                    expectedAst =
                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ UnionTypeDef







|







 







<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>






|
|
|

|
|

|
|
|
|
|
|

|
|

|
|
|
|
|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
...
716
717
718
719
720
721
722









723
724
725
726
727
728
729
...
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
import Dict.Extra as Dict
import Expect
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (SourceLocation, SourceLocationRange, emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST exposing (..)
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (addFunctionsForStructs, compile, compileRetainLocations, expectCompiles)


suite : Test
suite =
    describe "Parser"
        [ test "Sample program" <|
            \_ ->
................................................................................
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
            ]
        , test "Support code comments" <|
            \_ ->









                expectCompiles
                    """
                    # Increments the passed in value by one
                    def: inc
                    type: # as you'd expect
                      Int -- Int
                    : # again, pretty basic
................................................................................
                    type: Int -- Int
                    : 1
                      # + wouldnt work here
                      -

                    # And thats it!
                     # wonder what else we should do...
                    """
        , test "definition without implementation should be legal" <|
            \_ ->
                expectCompiles
                    """
                    def: someword
                    """
        , test "Correct line information" <|
            \_ ->
                let
                    source =
                        """
                        defunion: Bool
                        : True
                        : False

                        defstruct: True
                        defstruct: False

                        defmulti: from-int
                        type: Int -- Int
                        : Int( value 0 )
                          False
                        : Int
                          True

                        def: equal
                        : - from-int not

                        defmulti: not
                        : True
                          False
                        else: True
                        """

                    -- The ending source location for most definitions now ends where the next definition beings
                    -- This is not what we want (it includes too much white space), but it'll do for now.
                    expectedAst =
                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ UnionTypeDef

Modified tests/Test/Parser/Util.elm from [a86a98ba7a] to [34556264c0].

1
2
3
4

5
6
7
8

9
10
11
12
13
14
15
...
169
170
171
172
173
174
175










module Test.Parser.Util exposing
    ( addFunctionsForStructs
    , compile
    , compileRetainLocations

    )

import Dict
import Dict.Extra as Dict

import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type exposing (Type)
import Play.Parser as AST exposing (..)
import Play.Parser.Problem exposing (Problem)
import String.Extra as String

................................................................................

        allFuncs =
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }














>




>







 







>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
module Test.Parser.Util exposing
    ( addFunctionsForStructs
    , compile
    , compileRetainLocations
    , expectCompiles
    )

import Dict
import Dict.Extra as Dict
import Expect
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type exposing (Type)
import Play.Parser as AST exposing (..)
import Play.Parser.Problem exposing (Problem)
import String.Extra as String

................................................................................

        allFuncs =
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }


expectCompiles : String -> Expect.Expectation
expectCompiles code =
    case compile code of
        Err _ ->
            Expect.fail "Did not expect compilation to fail."

        Ok _ ->
            Expect.pass