Binding tests imlemented and skipped

This commit is contained in:
Umur Ozkul 2022-04-17 20:32:47 +02:00
parent e2015e1098
commit 52ac2e2ece
2 changed files with 90 additions and 21 deletions

View File

@ -19,37 +19,54 @@ let expectEvalToBe = (expr: string, answer: string) =>
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) => let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
Reducer.evaluateWBindings(expr, bindings)->ExpressionValue.toStringResult->expect->toBe(answer) Reducer.evaluateWBindings(expr, bindings)->ExpressionValue.toStringResult->expect->toBe(answer)
let expectEvalPartialBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) => let expectEvalPartialBindingsToBe = (
Reducer.evaluatePartialWBindings(expr, bindings)->ExpressionValue.toStringResultRecord->expect->toBe(answer) expr: string,
bindings: Reducer.externalBindings,
answer: string,
) =>
Reducer.evaluatePartialWBindings(expr, bindings)
->ExpressionValue.toStringResultRecord
->expect
->toBe(answer)
let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer)) let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer))
let testParseOuterToBe = (expr, answer) => test(expr, () => expectParseOuterToBe(expr, answer)) let testParseOuterToBe = (expr, answer) => test(expr, () => expectParseOuterToBe(expr, answer))
let testParsePartialToBe = (expr, answer) => test(expr, () => expectParsePartialToBe(expr, answer)) let testParsePartialToBe = (expr, answer) => test(expr, () => expectParsePartialToBe(expr, answer))
let testDescriptionParseToBe = (desc, expr, answer) => let testDescriptionParseToBe = (desc, expr, answer) =>
test(desc, () => expectParseToBe(expr, answer)) test(desc, () => expectParseToBe(expr, answer))
let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer)) let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer))
let testDescriptionEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, answer)) let testDescriptionEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, answer))
let testEvalBindingsToBe = (expr, bindingsList, answer) => let testEvalBindingsToBe = (expr, bindingsList, answer) =>
test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) => let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
module MySkip = { module MySkip = {
let testParseToBe = (expr, answer) => Skip.test(expr, () => expectParseToBe(expr, answer))
let testParseOuterToBe = (expr, answer) =>
Skip.test(expr, () => expectParseOuterToBe(expr, answer))
let testParsePartialToBe = (expr, answer) =>
Skip.test(expr, () => expectParsePartialToBe(expr, answer))
let testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, answer)) let testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, answer))
let testEvalBindingsToBe = (expr, bindingsList, answer) => let testEvalBindingsToBe = (expr, bindingsList, answer) =>
Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) => let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
Skip.test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) Skip.test(expr, () =>
expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)
)
} }
module MyOnly = { module MyOnly = {
let testParseToBe = (expr, answer) => Only.test(expr, () => expectParseToBe(expr, answer))
let testParseOuterToBe = (expr, answer) =>
Only.test(expr, () => expectParseOuterToBe(expr, answer))
let testParsePartialToBe = (expr, answer) =>
Only.test(expr, () => expectParsePartialToBe(expr, answer))
let testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer)) let testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer))
let testEvalBindingsToBe = (expr, bindingsList, answer) => let testEvalBindingsToBe = (expr, bindingsList, answer) =>
Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) => let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
Only.test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) Only.test(expr, () =>
expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)
)
} }

View File

@ -1,20 +1,72 @@
open Jest open Jest
open Reducer_TestHelpers open Reducer_TestHelpers
Skip.describe("Parse for Bindings", () => {
testParseOuterToBe(
"x",
"????",
)
testParseOuterToBe(
"x+1",
"????",
)
testParseOuterToBe(
"y = x+1; y",
"????",
)
testParsePartialToBe(
"x",
"????",
)
testParsePartialToBe(
"y=x",
"????",
)
testParsePartialToBe(
"y=x+1",
"????",
)
testParsePartialToBe(
"y = x+1; z = y",
"????",
)
})
describe("external bindings", () => { Skip.describe("Eval for Bindings", () => {
MySkip.testEvalBindingsToBe( testEvalBindingsToBe(
"y=1; x+1", "x",
list{("x", ExpressionValue.EvNumber(1.))}, list{("x", ExpressionValue.EvNumber(1.))},
"Ok(2)", "????",
) )
MySkip.testEvalBindingsToBe( testEvalBindingsToBe(
// This will go away when we have a proper parser
// x+1 is an expression not a block!
// Bindings are done for blocks only
"x+1", "x+1",
list{("x", ExpressionValue.EvNumber(1.))}, list{("x", ExpressionValue.EvNumber(1.))},
"Error(JS Exception: Error: Undefined symbol x)", "????",
) )
MySkip.testEvalToBe("x=1; y=1", "???") testEvalBindingsToBe(
}) "y = x+1; y",
list{("x", ExpressionValue.EvNumber(1.))},
"????",
)
testEvalPartialBindingsToBe(
"x",
list{("x", ExpressionValue.EvNumber(1.))},
"????",
)
testEvalPartialBindingsToBe(
"y=x",
list{("x", ExpressionValue.EvNumber(1.))},
"????",
)
testEvalBindingsToBe(
"y=x+1",
list{("x", ExpressionValue.EvNumber(1.))},
"????",
)
testEvalBindingsToBe(
"y = x+1; z = y",
list{("x", ExpressionValue.EvNumber(1.))},
"????",
)
})