Skip to content

Commit

Permalink
refactor(test): defer math ast parsing in normalized ast fold
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce committed Nov 30, 2024
1 parent 8430125 commit 3a02618
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/functionality/r-bridge/normalize-ast-fold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import type { RExpressionList } from '../../../src/r-bridge/lang-4.x/ast/model/n

describe('normalize-visitor', withShell(shell => {
let normalized: NormalizedAst | undefined;
let mathAst: NormalizedAst | undefined;
beforeAll(async() => {
normalized = await retrieveNormalizedAst(shell, 'x <- 42\ny <- "hello world"\nprint("foo")');
mathAst = await retrieveNormalizedAst(shell, '1 + 3 * 2');

});
test('find the number', () => {
let marker = false;
Expand Down Expand Up @@ -42,7 +45,7 @@ describe('normalize-visitor', withShell(shell => {
const result = astFold.fold(normalized?.ast);
expect(result).toBe(2);
});
test('do basic math (monoid)', async() => {
test('do basic math (monoid)', () => {
class MyMathFold<Info> extends DefaultNormalizedAstFold<number, Info> {
constructor() {
super(0);
Expand All @@ -67,11 +70,10 @@ describe('normalize-visitor', withShell(shell => {
}
}
const astFold = new MyMathFold();
const math = await retrieveNormalizedAst(shell, '1 + 3 * 2');
const result = astFold.fold(math?.ast);
const result = astFold.fold(mathAst?.ast);
expect(result).toBe(7);
});
test('fold should stop if overwritten and no continue', async() => {
test('fold should stop if overwritten and no continue', () => {
let foundNumber = false;
class MyMathFold<Info> extends DefaultNormalizedAstFold<void, Info> {
override foldRNumber(_node: RNumber<Info>) {
Expand All @@ -83,8 +85,7 @@ describe('normalize-visitor', withShell(shell => {
}
}
const astFold = new MyMathFold();
const math = await retrieveNormalizedAst(shell, '1 + 3 * 2');
astFold.fold(math?.ast);
astFold.fold(mathAst?.ast);
expect(foundNumber).toBe(false);
});
}));

0 comments on commit 3a02618

Please sign in to comment.