From 22e45d0e7bff76ad5e495c00ffaadd1e00252064 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Tue, 23 Aug 2022 13:39:19 +0200 Subject: [PATCH] tutorial injecting user values --- ...oject_tutorial_3_injecting_user_values.res | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_injecting_user_values.res diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_injecting_user_values.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_injecting_user_values.res new file mode 100644 index 00000000..f47396b0 --- /dev/null +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_injecting_user_values.res @@ -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 that depends on values from the UI */ + let project = Project.createProject() + Project.setSource(project, "main", "x+y+z") + /* x, y and z is not defined in the project but they has to come from the user */ + test("Injecting user values", () => { + /* User has input the values */ + let x = 1 + let y = 2 + let z = 3 + /* Then we construct a source code to define those values */ + let userCode = ` + x = ${x->Js.Int.toString} + y = ${y->Js.Int.toString} + z = ${z->Js.Int.toString} + ` + /* We inject the user code into the project */ + Project.setSource(project, "userCode", userCode) + /* "main" is depending on the user code */ + Project.setContinues(project, "main", ["userCode"]) + /* We can now run the project */ + Project.runAll(project) + let result = Project.getResult(project, "main") + result->InternalExpressionValue.toStringOptionResult->expect == "Ok(6)" + }) +}) + +/* Note that this is not final version of the project */ +/* In the future, for safety, we will provide a way to inject values instead of a source code */ +/* But time is limited for now... */