-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tengs Penkwe
committed
Feb 2, 2024
1 parent
7af7677
commit ea3f2f9
Showing
3 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,54 @@ | ||
import {expect, use} from "chai"; | ||
import { expect } from "chai"; | ||
import { typeToString, Result } from "../../src/ast/Type"; | ||
import * as sinon from "sinon"; | ||
|
||
describe("Type System", () => { | ||
describe("typeToString", () => { | ||
it("should correctly identify numbers", () => { | ||
expect(typeToString(42)).to.equal("Num"); | ||
}); | ||
|
||
it("should correctly identify strings", () => { | ||
expect(typeToString("Hello")).to.equal("String"); | ||
}); | ||
|
||
it("should correctly identify boolean values", () => { | ||
expect(typeToString(true)).to.equal("Bool"); | ||
expect(typeToString(false)).to.equal("Bool"); | ||
}); | ||
|
||
it("should handle null values", () => { | ||
expect(typeToString(null)).to.equal("Null"); | ||
}); | ||
|
||
}); | ||
|
||
describe("Result class", () => { | ||
it("should store and return the correct type and value", () => { | ||
const numResult = new Result("Num", 123); | ||
expect(numResult.type).to.equal("Num"); | ||
expect(numResult.value).to.equal(123); | ||
|
||
const boolResult = new Result("Bool", true); | ||
expect(boolResult.type).to.equal("Bool"); | ||
expect(boolResult.value).to.equal(true); | ||
}); | ||
|
||
it("should display the correct information with show()", () => { | ||
let spy = sinon.spy(console, "log"); | ||
const stringResult = new Result("String", "Test"); | ||
stringResult.show(); | ||
expect(spy.calledWith("Test")).to.be.true; | ||
spy.restore(); // Clean up the spy | ||
|
||
spy = sinon.spy(console, "log"); | ||
const nullResult = new Result("Null", null); | ||
nullResult.show(); | ||
expect(spy.called).to.be.false; | ||
spy.restore(); // Clean up the spy | ||
}); | ||
|
||
describe("Type", () => { | ||
it("should convert types to strings", () => { | ||
expect("a").to.equal("a"); | ||
}); | ||
|
||
}); | ||
|