Skip to content

Commit

Permalink
Add extra test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
davazp committed Jul 27, 2019
1 parent 5e6300a commit af64605
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
*fixtures*
dist-test
dist-test
dist-ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ yarn-error.log
coverage
.vscode
.delisp/
dist-ts/
25 changes: 25 additions & 0 deletions packages/delisp-core/__tests__/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ function evaluateString(str: string): unknown {
}

describe("Evaluation", () => {
describe("Booleans", () => {
it("should self-evaluate", () => {
expect(evaluateString("true")).toBe(true);
expect(evaluateString("false")).toBe(false);
});
});

describe("Numbers", () => {
it("should self-evaluate", () => {
expect(evaluateString("0")).toBe(0);
Expand Down Expand Up @@ -169,4 +176,22 @@ describe("Evaluation", () => {
).toBe(10);
});
});

describe("Match and case", () => {
it("should do basic pattern matching", () => {
expect(
evaluateString(`
(match (case :increase 10)
({:increase x} (+ x 1))
({:decrease x} (- x 1)))`)
).toBe(11);

expect(
evaluateString(`
(match (case :decrease 10)
({:increase x} (+ x 1))
({:decrease x} (- x 1)))`)
).toBe(9);
});
});
});
10 changes: 10 additions & 0 deletions packages/delisp-core/src/__snapshots__/type-convert.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ Object {
}
`;

exports[`convertType Effects extensible effects can't be written with | separator 1`] = `
"
Wrong effect separator"
`;

exports[`convertType Effects should convert effect with multiple labels 1`] = `
Object {
"node": Object {
Expand Down Expand Up @@ -412,6 +417,11 @@ Object {
}
`;

exports[`convertType extensible records can't be written with | separator 1`] = `
"
Expected record extension operator \\"<|\\", but found \\"|."
`;

exports[`convertType should detect incorrect types 1`] = `
"
file:1:1: Not a valid type
Expand Down
7 changes: 0 additions & 7 deletions packages/delisp-core/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ function compileVariable(
env: Environment,
_multipleValues: boolean
): JS.Expression {
if (ref.node.name === "true") {
return literal(true);
}
if (ref.node.name === "false") {
return literal(false);
}

const binding = lookupBinding(ref.node.name, env);
if (!binding) {
if (isInlinePrimitive(ref.node.name)) {
Expand Down
12 changes: 12 additions & 0 deletions packages/delisp-core/src/type-convert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ describe("convertType", () => {
expect(readAndConvert(" b ")).toMatchObject(T.var("b"));
});

it("should convert void", () => {
expect(readAndConvert("void")).toMatchObject(T.void);
});

it("should convert to functions", () => {
expect(readAndConvert(" (-> string _ number) ")).toMatchObject(
T.fn([T.string], T.var("_"), T.number)
Expand All @@ -59,6 +63,10 @@ describe("convertType", () => {
expect(readAndConvert("{:x number :y number <| a}")).toMatchSnapshot();
});

it("extensible records can't be written with | separator", () => {
expect(failedType("{:x number :y number | a}")).toMatchSnapshot();
});

it("should fail for invalid syntax of extensible records", () => {
expect(() => {
readAndConvert("{<| a :x number}");
Expand Down Expand Up @@ -95,6 +103,10 @@ describe("convertType", () => {
it("should convert open effect with multiple labels", () => {
expect(readAndConvert("(effect console async <| a)")).toMatchSnapshot();
});

it("extensible effects can't be written with | separator", () => {
expect(failedType("(effect console | a)")).toMatchSnapshot();
});
});

describe("Cases", () => {
Expand Down

0 comments on commit af64605

Please sign in to comment.