tutorial intro to includes

This commit is contained in:
Umur Ozkul 2022-08-23 09:35:29 +02:00
parent f23e26fbbf
commit a394e93e06
2 changed files with 49 additions and 1 deletions

View File

@ -63,5 +63,54 @@ Case "Running multiple sources"
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
}) })
test("Intro to including", () => {
/* Though it would not be practical for a storybook,
let's write the same project above with includes.
You will see that parsing includes is setting the dependencies the same way as before.
*/
let project = Project.createProject()
/* This time source1 and source2 are not depending on anything */
Project.setSource(project, "source1", "x=1")
Project.setSource(project, "source2", "y=2")
Project.setSource(
project,
"source3",
`
#include "source1"
#include "source2"
z=3`,
)
/* We need to parse the includes to set the dependencies */
Project.parseIncludes(project, "source3")
/* Now we can run the project */
Project.runAll(project)
/* And let's check the result and bindings of source3
This time you are getting all the variables because we are including the other sources
Behind the scenes parseIncludes is setting the dependencies */
let result3 = Project.getResult(project, "source3")
let bindings3 = Project.getBindings(project, "source3")
(
result3->InternalExpressionValue.toStringOptionResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
/*
Doing it like this is too verbose for a storybook
But I hope you have seen the relation of setContinues and parseIncludes
*/
/*
Dealing with includes needs more.
- There are parse errors
- There are cyclic includes
- And the depended source1 and source2 is not already there in the project
- If you knew the includes before hand there would not be point of the include directive.
More on those on the next section.
*/
})
}) })
}) })

View File

@ -21,4 +21,3 @@
@genType type pointSetDistribution = ForTS_Distribution_PointSetDistribution.pointSetDistribution //re-export @genType type pointSetDistribution = ForTS_Distribution_PointSetDistribution.pointSetDistribution //re-export
@genType type sampleSetDistribution = ForTS_Distribution_SampleSetDistribution.sampleSetDistribution //re-export @genType type sampleSetDistribution = ForTS_Distribution_SampleSetDistribution.sampleSetDistribution //re-export
@genType type symbolicDistribution = ForTS_Distribution_SymbolicDistribution.symbolicDistribution //re-export @genType type symbolicDistribution = ForTS_Distribution_SymbolicDistribution.symbolicDistribution //re-export