Start stubbing out Pratt parser - parse integers

This commit is contained in:
Tangent 2024-05-17 20:26:54 -04:00
parent 20b6624ed7
commit 62593b0ab8
2 changed files with 113 additions and 4 deletions

23
src/lib/expr.test.ts Normal file
View file

@ -0,0 +1,23 @@
import { AsText, TextPiece } from "../words";
import { Expr } from "./expr";
describe("expr", () => {
test.each([
["1", "1"],
// ["1 + 2", "3"],
// ["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
});