prototype-3x5/src/lib/expr.test.ts

24 lines
618 B
TypeScript
Raw Normal View History

import { AsText, TextPiece } from "../words";
import { Expr } from "./expr";
describe("expr", () => {
test.each([
["1", "1"],
2024-05-17 20:50:54 -04:00
["1 + 2", "3"],
2024-05-17 20:52:33 -04:00
["1 - 2", "-1"],
["1 * 2", "2"],
["1 / 2", "0.5"],
["1 // 2", "0"],
// TODO: operator precedence
// TODO: parentheses
// TODO; eror reporting
])("Expr does math: %s", (expression, result) => {
const actualResult = Expr({}, [{ text: expression }]);
console.log(actualResult)
expect("error" in actualResult).toBeFalsy();
expect(AsText(actualResult as TextPiece)).toEqual(result);
});
// TODO: handle expr prefix
});