Stabel

Check-in [3dc236ef66]
Login
Overview
Comment:Fixed remaining Elm tests.
Timelines: family | ancestors | descendants | both | builtin-rewrite
Files: files | file ages | folders
SHA3-256: 3dc236ef663d054eab59f3036dbd83af5e8d784c86e93cfb0e556c708dcc519a
User & Date: robin.hansen on 2021-09-30 16:52:24
Other Links: branch diff | manifest | tags
Context
2021-10-06
15:42
Include standard_library when running integration tests. Some tests still fail. check-in: 8175ad89cd user: robin.hansen tags: builtin-rewrite
2021-09-30
16:52
Fixed remaining Elm tests. check-in: 3dc236ef66 user: robin.hansen tags: builtin-rewrite
2021-09-29
19:50
Fix most Elm-based tests. check-in: a382b579ce user: robin.hansen tags: builtin-rewrite
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/PackageLoader.elm from [b7a13acee6] to [5a1cd4c46c].

36
37
38
39
40
41
42


43
44
45
46
47
48
49
..
75
76
77
78
79
80
81
82
83
84
85



86
87
88
89
90
91
92
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
125
126
127
128
129
130
131



132
133
134
135
136
137
138
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187







































188
189
190
191
192
193
194
...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317






318
319
320
321
322
323
324
...
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
...
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
...
431
432
433
434
435
436
437
438


439
440
441
442
443
444
445
...
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
...
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
...
629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
...
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
                        , PackageLoader.ResolveDirectories "/project/lib/template_strings/lib"
                        , PackageLoader.ReadFile "/project/lib/template_strings/lib/version" "stabel.json"
                        , PackageLoader.ReadFile "/project/lib/unused" "stabel.json"
                        , PackageLoader.ReadFile "/project/lib/version" "stabel.json"
                        , PackageLoader.ResolvePackageModules "robheghan/fnv" "/project"
                        , PackageLoader.ResolvePackageModules "jarvis/template_strings" "/project/lib/template_strings"
                        , PackageLoader.ResolvePackageModules "stabel/version" "/project/lib/template_strings/lib/version"


                        , PackageLoader.ReadFile "/project/src" "mod1.stbl"
                        , PackageLoader.ReadFile "/project/lib/template_strings/lib/version/src/version" "data.stbl"
                        ]
        , test "Compiles project with external dependencies to qualified AST" <|
            \_ ->
                let
                    loaderResult =
................................................................................
                                      , exposed = True
                                      , sourceLocation = Nothing
                                      , typeSignature = TypeSignature.NotProvided
                                      , implementation =
                                            Qualifier.SoloImpl
                                                [ Qualifier.Function emptyRange numberDef
                                                , Qualifier.Integer emptyRange 1
                                                , Qualifier.Builtin emptyRange Builtin.Plus
                                                ]
                                      }
                                    , numberDef



                                    ]
                            , referenceableFunctions = Set.empty
                            }
                            (Util.stripLocations ast)
        , test "Compiles project with multiple dependant modules to qualified AST" <|
            \_ ->
                let
................................................................................
                        { name = "/robheghan/dummy/mod1/bump-version"
                        , exposed = True
                        , sourceLocation = Nothing
                        , typeSignature = TypeSignature.NotProvided
                        , implementation =
                            Qualifier.SoloImpl
                                [ Qualifier.Integer emptyRange 1
                                , Qualifier.Builtin emptyRange Builtin.Plus
                                ]
                        }

                    versionDef =
                        { name = "/robheghan/dummy/mod2/version"
                        , exposed = True
                        , sourceLocation = Nothing
................................................................................
                    Ok ast ->
                        Expect.equal
                            { types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ versionDef
                                    , bumpVersionDef



                                    , { name = "/robheghan/dummy/mod3/next-version"
                                      , exposed = True
                                      , sourceLocation = Nothing
                                      , typeSignature = TypeSignature.NotProvided
                                      , implementation =
                                            Qualifier.SoloImpl
                                                [ Qualifier.Function emptyRange versionDef
................................................................................
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err _ ->
                            Expect.fail "Did not expect failure"

                        Ok _ ->
                            Expect.pass
            ]
        ]









































expectSideEffects : Dict String String -> List PackageLoader.SideEffect -> PackageLoader.Model -> Expectation
expectSideEffects fileSystem expectedSFs model =
    case resolveSideEffects fileSystem [] model of
        Err msg ->
            Expect.fail msg

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

stdLibFiles : Dict String String
stdLibFiles =
    Dict.fromList
        [ ( "/project/lib/unused/stabel.json"
          , """
            {
                "name": "some/useless",
                "version": "1.7.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "useless/mod"
                ],
                "dependencies": {
                },
                "package-paths": [
                ]
            }
          """
          )
        , ( "/project/lib/unused/src/useless/mod.stbl"
          , """
            def: square
            : dup *






            """
          )
        ]


testFiles : Dict String String
testFiles =
................................................................................
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "mod1"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0",
                    "stabel/version": "1.0.0"

                },
                "package-paths": [
                    "lib/template_strings",
                    "lib/version"
                ]
            }
            """
................................................................................
                "name": "jarvis/template_strings",
                "version": "1.2.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "template_strings/mod"
                ],
                "dependencies": {
                    "stabel/version": "1.1.0"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
          """
          )
................................................................................
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "mod1",
                    "mod2",
                    "mod3"
                ],
                "dependencies": {},


                "package-paths": []
            }
            """
          )
        , ( "/project/src/mod1.stbl"
          , """
            def: bump-version
................................................................................
                "name": "robheghan/dummy",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "core"
                ],
                "dependencies": {
                    "robheghan/pack": "1.0.0"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "pub"
                ],
                "dependencies": {
                    "robheghan/utils": "1.0.1"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "pub"
                ],
                "dependencies": {
                    "robheghan/utils": "1.0.1"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
        [ ( "/project/stabel.json"
          , """
            {
                "name": "robheghan/dummy",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "core"
                ],
                "dependencies": {
                    "robheghan/pack": "1.0.0"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
        , ( "/project/src/core.stbl"
          , """
            def: test
            : /core/number-five 4 +
            """
          )
        , ( "/project/lib/pack/stabel.json"
          , """
            {
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "core"
                ],
                "dependencies": {},
                "package-paths": []
            }
            """
          )
        , ( "/project/lib/pack/src/core.stbl"
          , """
            def: number-five
            : 5
            """
          )
        ]
        |> Dict.union stdLibFiles







>
>







 







|



>
>
>







 







|







 







>
>
>







 







|
|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|


|








|

|
|
>
>
>
>
>
>







 







|
>







 







|
>







 







|
>
>







 







|
>







 







|
>







 







|
>







 







|


|
>







|


|









|






|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
...
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
...
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
...
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
784
785
                        , PackageLoader.ResolveDirectories "/project/lib/template_strings/lib"
                        , PackageLoader.ReadFile "/project/lib/template_strings/lib/version" "stabel.json"
                        , PackageLoader.ReadFile "/project/lib/unused" "stabel.json"
                        , PackageLoader.ReadFile "/project/lib/version" "stabel.json"
                        , PackageLoader.ResolvePackageModules "robheghan/fnv" "/project"
                        , PackageLoader.ResolvePackageModules "jarvis/template_strings" "/project/lib/template_strings"
                        , PackageLoader.ResolvePackageModules "stabel/version" "/project/lib/template_strings/lib/version"
                        , PackageLoader.ReadFile "/project/lib/unused/src" "core.stbl"
                        , PackageLoader.ResolvePackageModules "stabel/standard_library" "/project/lib/unused"
                        , PackageLoader.ReadFile "/project/src" "mod1.stbl"
                        , PackageLoader.ReadFile "/project/lib/template_strings/lib/version/src/version" "data.stbl"
                        ]
        , test "Compiles project with external dependencies to qualified AST" <|
            \_ ->
                let
                    loaderResult =
................................................................................
                                      , exposed = True
                                      , sourceLocation = Nothing
                                      , typeSignature = TypeSignature.NotProvided
                                      , implementation =
                                            Qualifier.SoloImpl
                                                [ Qualifier.Function emptyRange numberDef
                                                , Qualifier.Integer emptyRange 1
                                                , Qualifier.Function emptyRange plusDef
                                                ]
                                      }
                                    , numberDef
                                    , plusDef
                                    , minusDef
                                    , equalDef
                                    ]
                            , referenceableFunctions = Set.empty
                            }
                            (Util.stripLocations ast)
        , test "Compiles project with multiple dependant modules to qualified AST" <|
            \_ ->
                let
................................................................................
                        { name = "/robheghan/dummy/mod1/bump-version"
                        , exposed = True
                        , sourceLocation = Nothing
                        , typeSignature = TypeSignature.NotProvided
                        , implementation =
                            Qualifier.SoloImpl
                                [ Qualifier.Integer emptyRange 1
                                , Qualifier.Function emptyRange plusDef
                                ]
                        }

                    versionDef =
                        { name = "/robheghan/dummy/mod2/version"
                        , exposed = True
                        , sourceLocation = Nothing
................................................................................
                    Ok ast ->
                        Expect.equal
                            { types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ versionDef
                                    , bumpVersionDef
                                    , plusDef
                                    , minusDef
                                    , equalDef
                                    , { name = "/robheghan/dummy/mod3/next-version"
                                      , exposed = True
                                      , sourceLocation = Nothing
                                      , typeSignature = TypeSignature.NotProvided
                                      , implementation =
                                            Qualifier.SoloImpl
                                                [ Qualifier.Function emptyRange versionDef
................................................................................
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err err ->
                            Expect.fail <| Debug.log "err" err

                        Ok _ ->
                            Expect.pass
            ]
        ]


plusDef : Qualifier.FunctionDefinition
plusDef =
    { name = "/stabel/standard_library/core/+"
    , exposed = True
    , sourceLocation = Nothing
    , typeSignature = TypeSignature.NotProvided
    , implementation =
        Qualifier.SoloImpl
            [ Qualifier.Builtin emptyRange Builtin.Plus
            ]
    }


minusDef : Qualifier.FunctionDefinition
minusDef =
    { name = "/stabel/standard_library/core/-"
    , exposed = True
    , sourceLocation = Nothing
    , typeSignature = TypeSignature.NotProvided
    , implementation =
        Qualifier.SoloImpl
            [ Qualifier.Builtin emptyRange Builtin.Minus
            ]
    }


equalDef : Qualifier.FunctionDefinition
equalDef =
    { name = "/stabel/standard_library/core/="
    , exposed = True
    , sourceLocation = Nothing
    , typeSignature = TypeSignature.NotProvided
    , implementation =
        Qualifier.SoloImpl
            [ Qualifier.Builtin emptyRange Builtin.Equal
            ]
    }


expectSideEffects : Dict String String -> List PackageLoader.SideEffect -> PackageLoader.Model -> Expectation
expectSideEffects fileSystem expectedSFs model =
    case resolveSideEffects fileSystem [] model of
        Err msg ->
            Expect.fail msg

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

stdLibFiles : Dict String String
stdLibFiles =
    Dict.fromList
        [ ( "/project/lib/unused/stabel.json"
          , """
            {
                "name": "stabel/standard_library",
                "version": "0.3.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "core"
                ],
                "dependencies": {
                },
                "package-paths": [
                ]
            }
          """
          )
        , ( "/project/lib/unused/src/core.stbl"
          , """
            def: +
            : //stabel/hidden/int/+

            def: -
            : //stabel/hidden/int/-

            def: =
            : //stabel/hidden/int/=
            """
          )
        ]


testFiles : Dict String String
testFiles =
................................................................................
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "mod1"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0",
                    "stabel/version": "1.0.0",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/template_strings",
                    "lib/version"
                ]
            }
            """
................................................................................
                "name": "jarvis/template_strings",
                "version": "1.2.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "template_strings/mod"
                ],
                "dependencies": {
                    "stabel/version": "1.1.0",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
          """
          )
................................................................................
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "mod1",
                    "mod2",
                    "mod3"
                ],
                "dependencies": {
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": []
            }
            """
          )
        , ( "/project/src/mod1.stbl"
          , """
            def: bump-version
................................................................................
                "name": "robheghan/dummy",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "core"
                ],
                "dependencies": {
                    "robheghan/pack": "1.0.0",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "pub"
                ],
                "dependencies": {
                    "robheghan/utils": "1.0.1",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "pub"
                ],
                "dependencies": {
                    "robheghan/utils": "1.0.1",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
        [ ( "/project/stabel.json"
          , """
            {
                "name": "robheghan/dummy",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "module"
                ],
                "dependencies": {
                    "robheghan/pack": "1.0.0",
                    "stabel/standard_library": "0.3.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
        , ( "/project/src/module.stbl"
          , """
            def: test
            : /module/number-five 4 +
            """
          )
        , ( "/project/lib/pack/stabel.json"
          , """
            {
                "name": "robheghan/pack",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "module"
                ],
                "dependencies": {},
                "package-paths": []
            }
            """
          )
        , ( "/project/lib/pack/src/module.stbl"
          , """
            def: number-five
            : 5
            """
          )
        ]
        |> Dict.union stdLibFiles