Skip to content

Commit

Permalink
test : array literal parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yazaldefilimone committed Feb 25, 2024
1 parent 1fca3c4 commit a57aa0c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/parser/tests/array-literal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { it, expect, describe } from "vitest";
import { makeSut } from "./sut";
import { ExpressionStatement } from "ast";
import { ArrayLiteral } from "ast/array";
describe("Parser", () => {
describe("Parse program", () => {
it("Array literal", () => {
const code = `
[1, 2 * 2, 3 + 3, "hello"];
`;
const { program } = makeSut(code, {
isLogError: true,
toString: false,
});
const statement: ExpressionStatement = program.statements[0] as any;
expect(statement).instanceOf(ExpressionStatement);
const expression = statement.expression as any;
expect(expression).instanceOf(ArrayLiteral);
expect(expression.elements.length).toBe(4);
expect(expression.elements[0].value).toBe(1);
expect(expression.elements[1].toString()).toBe("(2 * 2)");
expect(expression.elements[2].toString()).toBe("(3 + 3)");
expect(expression.elements[3].value).toBe("hello");
});
});
});

0 comments on commit a57aa0c

Please sign in to comment.