Skip to content

Commit

Permalink
pin down truthiness
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Jan 14, 2024
1 parent 09cae29 commit a567301
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ describe("interpreter", () => {
expect(evaluate(`"hello" + " " + "world"`)).toEqual("hello world");
});

it("should evaluate truthiness", () => {
expect(evaluate("!true")).toEqual(false);
expect(evaluate("!12")).toEqual(false);
expect(evaluate("!!nil")).toEqual(false);
expect(evaluate("!!0")).toEqual(true);
expect(evaluate(`!!""`)).toEqual(true);
});

it("should report an error on mixed + operands", () => {
expect(() => evaluate(`"12" + 13`)).toThrowError(
"Operands must be two numbers or two strings.",
Expand Down

0 comments on commit a567301

Please sign in to comment.