From 52ac2e2eceac905eb146468ce550a52ebcb8d1a2 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Sun, 17 Apr 2022 20:32:47 +0200 Subject: [PATCH] Binding tests imlemented and skipped --- .../__tests__/Reducer/Reducer_TestHelpers.res | 33 ++++++-- .../Reducer/Reducer_externalBindings_test.res | 78 +++++++++++++++---- 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res index 76fe8c71..74c196f2 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res @@ -19,37 +19,54 @@ let expectEvalToBe = (expr: string, answer: string) => let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) => Reducer.evaluateWBindings(expr, bindings)->ExpressionValue.toStringResult->expect->toBe(answer) -let expectEvalPartialBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) => - Reducer.evaluatePartialWBindings(expr, bindings)->ExpressionValue.toStringResultRecord->expect->toBe(answer) +let expectEvalPartialBindingsToBe = ( + 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 testParseOuterToBe = (expr, answer) => test(expr, () => expectParseOuterToBe(expr, answer)) let testParsePartialToBe = (expr, answer) => test(expr, () => expectParsePartialToBe(expr, answer)) - let testDescriptionParseToBe = (desc, expr, answer) => test(desc, () => expectParseToBe(expr, answer)) let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer)) - let testDescriptionEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, answer)) - let testEvalBindingsToBe = (expr, bindingsList, answer) => test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) - let testEvalPartialBindingsToBe = (expr, bindingsList, answer) => test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)) 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 testEvalBindingsToBe = (expr, bindingsList, answer) => Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, 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 = { + 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 testEvalBindingsToBe = (expr, bindingsList, answer) => Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, 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) + ) } diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res index 4a52978a..844eba69 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res @@ -1,20 +1,72 @@ open Jest 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", () => { -MySkip.testEvalBindingsToBe( - "y=1; x+1", +Skip.describe("Eval for Bindings", () => { + testEvalBindingsToBe( + "x", list{("x", ExpressionValue.EvNumber(1.))}, - "Ok(2)", -) -MySkip.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 + "????", + ) + testEvalBindingsToBe( "x+1", list{("x", ExpressionValue.EvNumber(1.))}, - "Error(JS Exception: Error: Undefined symbol x)", -) -MySkip.testEvalToBe("x=1; y=1", "???") -}) \ No newline at end of file + "????", + ) + 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.))}, + "????", + ) +}) +