shorter tests

This commit is contained in:
Umur Ozkul 2022-04-05 19:36:19 +02:00
parent bbcd7f2640
commit 4e6a2341f0
2 changed files with 29 additions and 24 deletions

View File

@ -10,9 +10,15 @@ let expectParseToBe = (expr, answer) =>
let testParse = (expr, answer) => let testParse = (expr, answer) =>
test(expr, () => expectParseToBe(expr, answer)) test(expr, () => expectParseToBe(expr, answer))
let testDescParse = (desc, expr, answer) =>
test(desc, () => expectParseToBe(expr, answer))
let skipTestParse = (expr, answer) => let skipTestParse = (expr, answer) =>
Skip.test(expr, () => expectParseToBe(expr, answer)) Skip.test(expr, () => expectParseToBe(expr, answer))
let skipDescTestParse = (desc, expr, answer) =>
Skip.test(desc, () => expectParseToBe(expr, answer))
describe("MathJs parse", () => { describe("MathJs parse", () => {
describe("literals operators paranthesis", () => { describe("literals operators paranthesis", () => {
testParse("1", "1") testParse("1", "1")
@ -43,15 +49,15 @@ describe("MathJs parse", () => {
}) })
describe("records", () => { describe("records", () => {
test("define", () => expectParseToBe("{a: 1, b: 2}", "{a: 1, b: 2}")) testDescParse("define", "{a: 1, b: 2}", "{a: 1, b: 2}")
test("use", () => expectParseToBe("record.property", "record['property']")) testDescParse("use", "record.property", "record['property']")
}) })
describe("comments", () => { describe("comments", () => {
Skip.test("define", () => expectParseToBe("# This is a comment", "???")) skipDescTestParse("define", "# This is a comment", "???")
}) })
describe("if statement", () => { describe("if statement", () => {
Skip.test("define", () => expectParseToBe("if (true) { 1 } else { 0 }", "???")) skipDescTestParse("define", "if (true) { 1 } else { 0 }", "???")
}) })
}) })

View File

@ -1,12 +1,19 @@
open Jest open Jest
open Reducer_TestHelpers open Reducer_TestHelpers
let testParseToBe = (expr, answer) => let testParseToBe = (expr, answer) =>
test(expr, () => expectParseToBe(expr, answer)) test(expr, () => expectParseToBe(expr, answer))
let testDescParseToBe = (desc, expr, answer) =>
test(desc, () => expectParseToBe(expr, answer))
let testEvalToBe = (expr, answer) => let testEvalToBe = (expr, answer) =>
test(expr, () => expectEvalToBe(expr, answer)) test(expr, () => expectEvalToBe(expr, answer))
let testDescEvalToBe = (desc, expr, answer) =>
test(desc, () => expectEvalToBe(expr, answer))
describe("reducer using mathjs parse", () => { describe("reducer using mathjs parse", () => {
// Test the MathJs parser compatibility // Test the MathJs parser compatibility
// Those tests toString that there is a semantic mapping from MathJs to Expression // Those tests toString that there is a semantic mapping from MathJs to Expression
@ -27,21 +34,17 @@ describe("reducer using mathjs parse", () => {
//Note. () is a empty list in Lisp //Note. () is a empty list in Lisp
// The only builtin structure in Lisp is list. There are no arrays // The only builtin structure in Lisp is list. There are no arrays
// [1,2,3] becomes (1 2 3) // [1,2,3] becomes (1 2 3)
test("empty", () => expectParseToBe("[]", "Ok(())")) testDescParseToBe("empty", "[]", "Ok(())")
testParseToBe("[1, 2, 3]", "Ok((1 2 3))") testParseToBe("[1, 2, 3]", "Ok((1 2 3))")
testParseToBe("['hello', 'world']", "Ok(('hello' 'world'))") testParseToBe("['hello', 'world']", "Ok(('hello' 'world'))")
test("index", () => expectParseToBe("([0,1,2])[1]", "Ok((:$atIndex (0 1 2) (1)))")) testDescParseToBe("index", "([0,1,2])[1]", "Ok((:$atIndex (0 1 2) (1)))")
}) })
describe("records", () => { describe("records", () => {
test("define", () => testDescParseToBe("define",
expectParseToBe("{a: 1, b: 2}", "Ok((:$constructRecord (('a' 1) ('b' 2))))") "{a: 1, b: 2}", "Ok((:$constructRecord (('a' 1) ('b' 2))))")
) testDescParseToBe("use",
test("use", () =>
expectParseToBe(
"{a: 1, b: 2}.a", "{a: 1, b: 2}.a",
"Ok((:$atIndex (:$constructRecord (('a' 1) ('b' 2))) ('a')))", "Ok((:$atIndex (:$constructRecord (('a' 1) ('b' 2))) ('a')))")
)
)
}) })
}) })
@ -65,9 +68,8 @@ describe("eval", () => {
testEvalToBe("[1, 2, 3]", "Ok([1, 2, 3])") testEvalToBe("[1, 2, 3]", "Ok([1, 2, 3])")
testEvalToBe("['hello', 'world']", "Ok(['hello', 'world'])") testEvalToBe("['hello', 'world']", "Ok(['hello', 'world'])")
testEvalToBe("([0,1,2])[1]", "Ok(1)") testEvalToBe("([0,1,2])[1]", "Ok(1)")
test("index not found", () => testDescEvalToBe("index not found",
expectEvalToBe("([0,1,2])[10]", "Error(Array index not found: 10)") "([0,1,2])[10]", "Error(Array index not found: 10)")
)
}) })
describe("records", () => { describe("records", () => {
test("define", () => expectEvalToBe("{a: 1, b: 2}", "Ok({a: 1, b: 2})")) test("define", () => expectEvalToBe("{a: 1, b: 2}", "Ok({a: 1, b: 2})"))
@ -77,11 +79,8 @@ describe("eval", () => {
}) })
describe("test exceptions", () => { describe("test exceptions", () => {
test("javascript exception", () => testDescEvalToBe("javascript exception",
expectEvalToBe("jsraise('div by 0')", "Error(JS Exception: Error: 'div by 0')") "jsraise('div by 0')", "Error(JS Exception: Error: 'div by 0')")
) testDescEvalToBe("rescript exception",
"resraise()", "Error(TODO: unhandled rescript exception)")
test("rescript exception", () =>
expectEvalToBe("resraise()", "Error(TODO: unhandled rescript exception)")
)
}) })