tutorial calling functions
This commit is contained in:
parent
22e45d0e7b
commit
8de8cc3633
|
@ -0,0 +1,39 @@
|
||||||
|
@@warning("-44")
|
||||||
|
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
||||||
|
module Project = ForTS_ReducerProject
|
||||||
|
module Bindings = Reducer_Bindings
|
||||||
|
|
||||||
|
open Jest
|
||||||
|
open Expect
|
||||||
|
open Expect.Operators
|
||||||
|
|
||||||
|
describe("ReducerProject Tutorial", () => {
|
||||||
|
/* Let's build a project to provide a function. */
|
||||||
|
/* But we will call that function on an array of user input. */
|
||||||
|
let project = Project.createProject()
|
||||||
|
Project.setSource(project, "library", "double(x) = x * 2")
|
||||||
|
/* userCode is not here yet but its dependency is fixed. So we can set it once and for all */
|
||||||
|
Project.setContinues(project, "userCode", ["library"])
|
||||||
|
|
||||||
|
let userValues = [1, 2, 3, 4, 5]
|
||||||
|
|
||||||
|
let userResults = Belt.Array.map(userValues, aUserValue => {
|
||||||
|
let userCode = `double(${aUserValue->Js.Int.toString})`
|
||||||
|
/* Put the constructed source in the project */
|
||||||
|
/* We have already set that it depends on "library" */
|
||||||
|
Project.setSource(project, "userCode", userCode)
|
||||||
|
/* Run the project */
|
||||||
|
Project.runAll(project)
|
||||||
|
/* Get the result */
|
||||||
|
Project.getResult(project, "userCode")
|
||||||
|
/* I have to remind you that the "library" is run only once and for all.
|
||||||
|
The library is not run for each user value. */
|
||||||
|
})
|
||||||
|
|
||||||
|
test("userResults", () => {
|
||||||
|
let userResultsAsString = Belt.Array.map(userResults, aResult =>
|
||||||
|
aResult->InternalExpressionValue.toStringOptionResult
|
||||||
|
)
|
||||||
|
userResultsAsString->expect == ["Ok(2)", "Ok(4)", "Ok(6)", "Ok(8)", "Ok(10)"]
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user