2024-05-17 20:26:54 -04:00
|
|
|
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"],
|
2024-05-17 20:26:54 -04:00
|
|
|
// 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
|
|
|
|
});
|