shorter tests

This commit is contained in:
Umur Ozkul 2022-04-05 19:09:29 +02:00
parent c6b58423e0
commit 74da6a0ae2

View File

@ -7,32 +7,38 @@ open Expect
let expectParseToBe = (expr, answer) =>
Parse.parse(expr)->Result.flatMap(Parse.castNodeType)->Parse.toStringResult->expect->toBe(answer)
let testParse = (expr, answer) =>
test(expr, () => expectParseToBe(expr, answer))
let skipTestParse = (expr, answer) =>
Skip.test(expr, () => expectParseToBe(expr, answer))
describe("MathJs parse", () => {
describe("literals operators paranthesis", () => {
test("1", () => expectParseToBe("1", "1"))
test("'hello'", () => expectParseToBe("'hello'", "'hello'"))
test("true", () => expectParseToBe("true", "true"))
test("1+2", () => expectParseToBe("1+2", "add(1, 2)"))
test("add(1,2)", () => expectParseToBe("add(1,2)", "add(1, 2)"))
test("(1)", () => expectParseToBe("(1)", "(1)"))
test("(1+2)", () => expectParseToBe("(1+2)", "(add(1, 2))"))
testParse("1", "1")
testParse("'hello'", "'hello'")
testParse("true", "true")
testParse("1+2", "add(1, 2)")
testParse("add(1,2)", "add(1, 2)")
testParse("(1)", "(1)")
testParse("(1+2)", "(add(1, 2))")
})
describe("variables", () => {
Skip.test("define", () => expectParseToBe("x = 1", "???"))
Skip.test("use", () => expectParseToBe("x", "???"))
skipTestParse("x = 1", "???")
skipTestParse("x", "???")
})
describe("functions", () => {
Skip.test("define", () => expectParseToBe("identity(x) = x", "???"))
Skip.test("use", () => expectParseToBe("identity(x)", "???"))
skipTestParse("identity(x) = x", "???")
skipTestParse("identity(x)", "???")
})
describe("arrays", () => {
test("empty", () => expectParseToBe("[]", "[]"))
test("define", () => expectParseToBe("[0, 1, 2]", "[0, 1, 2]"))
test("define with strings", () => expectParseToBe("['hello', 'world']", "['hello', 'world']"))
Skip.test("range", () => expectParseToBe("range(0, 4)", "range(0, 4)"))
skipTestParse("range(0, 4)", "range(0, 4)")
test("index", () => expectParseToBe("([0,1,2])[1]", "([0, 1, 2])[1]"))
})