2022-07-25 14:34:33 +00:00
|
|
|
@@warning("-44")
|
2022-08-19 15:13:31 +00:00
|
|
|
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
|
|
|
module Project = ForTS_ReducerProject
|
2022-07-25 14:34:33 +00:00
|
|
|
module Bindings = Reducer_Bindings
|
|
|
|
|
|
|
|
open Jest
|
|
|
|
open Expect
|
|
|
|
open Expect.Operators
|
|
|
|
|
|
|
|
let runFetchResult = (project, sourceId) => {
|
|
|
|
Project.run(project, sourceId)
|
2022-08-25 08:43:51 +00:00
|
|
|
Project.getResult(project, sourceId)->InternalExpressionValue.toStringResult
|
2022-07-25 14:34:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 21:54:54 +00:00
|
|
|
let runFetchFlatBindings = (project, sourceId) => {
|
2022-07-25 14:34:33 +00:00
|
|
|
Project.run(project, sourceId)
|
2022-09-19 11:00:38 +00:00
|
|
|
Project.getBindings(project, sourceId)->InternalExpressionValue.toStringRecord
|
2022-07-25 14:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test("test result true", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "main", "true")
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(true)")
|
|
|
|
})
|
|
|
|
|
|
|
|
test("test result false", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "main", "false")
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(false)")
|
|
|
|
})
|
|
|
|
|
|
|
|
test("test library", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "main", "x=Math.pi; x")
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(3.141592653589793)")
|
|
|
|
})
|
|
|
|
|
|
|
|
test("test bindings", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "variables", "myVariable=666")
|
2022-09-17 22:19:08 +00:00
|
|
|
runFetchFlatBindings(project, "variables")->expect->toBe("{myVariable: 666}")
|
2022-07-25 14:34:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("project1", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "first", "x=1")
|
|
|
|
Project.setSource(project, "main", "x")
|
|
|
|
Project.setContinues(project, "main", ["first"])
|
|
|
|
|
|
|
|
test("runOrder", () => {
|
|
|
|
expect(Project.getRunOrder(project)) == ["first", "main"]
|
|
|
|
})
|
|
|
|
test("dependents first", () => {
|
|
|
|
expect(Project.getDependents(project, "first")) == ["main"]
|
|
|
|
})
|
|
|
|
test("dependencies first", () => {
|
|
|
|
expect(Project.getDependencies(project, "first")) == []
|
|
|
|
})
|
|
|
|
test("dependents main", () => {
|
|
|
|
expect(Project.getDependents(project, "main")) == []
|
|
|
|
})
|
|
|
|
test("dependencies main", () => {
|
|
|
|
expect(Project.getDependencies(project, "main")) == ["first"]
|
|
|
|
})
|
2022-08-31 21:54:54 +00:00
|
|
|
|
|
|
|
test("past chain first", () => {
|
2022-09-11 15:22:07 +00:00
|
|
|
expect(ReducerProject.getPastChain(project, "first")) == []
|
2022-08-31 21:54:54 +00:00
|
|
|
})
|
|
|
|
test("past chain main", () => {
|
2022-09-11 15:22:07 +00:00
|
|
|
expect(ReducerProject.getPastChain(project, "main")) == ["first"]
|
2022-08-31 21:54:54 +00:00
|
|
|
})
|
|
|
|
|
2022-07-25 14:34:33 +00:00
|
|
|
test("test result", () => {
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(1)")
|
|
|
|
})
|
|
|
|
test("test bindings", () => {
|
2022-09-17 22:19:08 +00:00
|
|
|
runFetchFlatBindings(project, "first")->expect->toBe("{x: 1}")
|
2022-07-25 14:34:33 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("project2", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setContinues(project, "main", ["second"])
|
|
|
|
Project.setContinues(project, "second", ["first"])
|
|
|
|
Project.setSource(project, "first", "x=1")
|
|
|
|
Project.setSource(project, "second", "y=2")
|
2022-09-17 22:19:08 +00:00
|
|
|
Project.setSource(project, "main", "z=3;y")
|
2022-07-25 14:34:33 +00:00
|
|
|
|
|
|
|
test("runOrder", () => {
|
|
|
|
expect(Project.getRunOrder(project)) == ["first", "second", "main"]
|
|
|
|
})
|
|
|
|
test("runOrderFor", () => {
|
|
|
|
expect(Project.getRunOrderFor(project, "first")) == ["first"]
|
|
|
|
})
|
|
|
|
test("dependencies first", () => {
|
|
|
|
expect(Project.getDependencies(project, "first")) == []
|
|
|
|
})
|
|
|
|
test("dependents first", () => {
|
|
|
|
expect(Project.getDependents(project, "first")) == ["second", "main"]
|
|
|
|
})
|
|
|
|
test("dependents main", () => {
|
|
|
|
expect(Project.getDependents(project, "main")) == []
|
|
|
|
})
|
|
|
|
test("dependencies main", () => {
|
|
|
|
expect(Project.getDependencies(project, "main")) == ["first", "second"]
|
|
|
|
})
|
|
|
|
test("test result", () => {
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(2)")
|
|
|
|
})
|
|
|
|
test("test bindings", () => {
|
2022-09-17 22:19:08 +00:00
|
|
|
// bindings from continues are not exposed!
|
|
|
|
runFetchFlatBindings(project, "main")->expect->toBe("{z: 3}")
|
2022-07-25 14:34:33 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("project with include", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setContinues(project, "main", ["second"])
|
|
|
|
Project.setContinues(project, "second", ["first"])
|
|
|
|
|
|
|
|
Project.setSource(
|
|
|
|
project,
|
|
|
|
"first",
|
|
|
|
`
|
|
|
|
#include 'common'
|
|
|
|
x=1`,
|
|
|
|
)
|
|
|
|
Project.parseIncludes(project, "first")
|
|
|
|
Project.parseIncludes(project, "first") //The only way of setting includes
|
|
|
|
//Don't forget to parse includes after changing the source
|
|
|
|
|
|
|
|
Project.setSource(project, "common", "common=0")
|
|
|
|
Project.setSource(
|
|
|
|
project,
|
|
|
|
"second",
|
|
|
|
`
|
|
|
|
#include 'common'
|
|
|
|
y=2`,
|
|
|
|
)
|
|
|
|
Project.parseIncludes(project, "second") //The only way of setting includes
|
|
|
|
|
2022-09-17 22:19:08 +00:00
|
|
|
Project.setSource(project, "main", "z=3; y")
|
2022-07-25 14:34:33 +00:00
|
|
|
|
|
|
|
test("runOrder", () => {
|
|
|
|
expect(Project.getRunOrder(project)) == ["common", "first", "second", "main"]
|
|
|
|
})
|
|
|
|
|
|
|
|
test("runOrderFor", () => {
|
|
|
|
expect(Project.getRunOrderFor(project, "first")) == ["common", "first"]
|
|
|
|
})
|
|
|
|
|
|
|
|
test("dependencies first", () => {
|
|
|
|
expect(Project.getDependencies(project, "first")) == ["common"]
|
|
|
|
})
|
|
|
|
test("dependents first", () => {
|
|
|
|
expect(Project.getDependents(project, "first")) == ["second", "main"]
|
|
|
|
})
|
|
|
|
test("dependents main", () => {
|
|
|
|
expect(Project.getDependents(project, "main")) == []
|
|
|
|
})
|
|
|
|
test("dependencies main", () => {
|
|
|
|
expect(Project.getDependencies(project, "main")) == ["common", "first", "second"]
|
|
|
|
})
|
|
|
|
test("test result", () => {
|
|
|
|
runFetchResult(project, "main")->expect->toBe("Ok(2)")
|
|
|
|
})
|
|
|
|
test("test bindings", () => {
|
2022-09-17 22:19:08 +00:00
|
|
|
// bindings from continues are not exposed!
|
|
|
|
runFetchFlatBindings(project, "main")->expect->toBe("{z: 3}")
|
2022-07-25 14:34:33 +00:00
|
|
|
})
|
|
|
|
})
|
2022-09-01 14:12:02 +00:00
|
|
|
|
|
|
|
describe("project with independent sources", () => {
|
|
|
|
let project = Project.createProject()
|
|
|
|
Project.setSource(project, "first", "1")
|
|
|
|
Project.setSource(project, "second", "2")
|
2022-09-04 19:24:53 +00:00
|
|
|
test("run order of first", () => {
|
2022-09-01 14:12:02 +00:00
|
|
|
expect(Project.getRunOrderFor(project, "first")) == ["first"]
|
|
|
|
})
|
2022-09-04 19:24:53 +00:00
|
|
|
test("run order of second", () => {
|
2022-09-01 14:12:02 +00:00
|
|
|
expect(Project.getRunOrderFor(project, "second")) == ["second"]
|
|
|
|
})
|
|
|
|
})
|