Start stubbing out Pratt parser - parse integers
This commit is contained in:
parent
20b6624ed7
commit
62593b0ab8
2 changed files with 113 additions and 4 deletions
src/lib
23
src/lib/expr.test.ts
Normal file
23
src/lib/expr.test.ts
Normal 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
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue