Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/testing/testing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Node} from "../model/model";
import {fail} from "assert";
import {expect} from "chai";
import {strictEqual,deepStrictEqual,fail} from "node:assert";

export function assertASTsAreEqual(
expected: Node,
Expand All @@ -10,7 +9,7 @@ export function assertASTsAreEqual(
): void {
if (areSameType(expected, actual)) {
if (considerPosition) {
expect(actual.position, `${context}.position`).to.eql(expected.position);
deepStrictEqual(actual.position, expected.position, `${context}.position`);
}
expected.features.forEach(expectedProperty => {
const actualPropValue = actual.features.find(p => p.name == expectedProperty.name)!.value;
Expand All @@ -25,10 +24,11 @@ export function assertASTsAreEqual(
);
}
else if (Array.isArray(actualPropValue) && Array.isArray(expectedPropValue)) {
expect(
strictEqual(
actualPropValue.length,
expectedPropValue.length,
`${context}, property ${expectedProperty.name} has length ${expectedPropValue.length}, but found ${actualPropValue.length}`
).to.equal(expectedPropValue.length)
);
for (let i = 0; i < expectedPropValue.length; i++) {
const expectedElement = expectedPropValue[i];
const actualElement = actualPropValue[i];
Expand All @@ -42,18 +42,20 @@ export function assertASTsAreEqual(
);
}
else if (typeof expectedElement != "object" && typeof actualElement != "object") {
expect(
strictEqual(
actualElement,
`${context}, property ${expectedProperty.name}[${i}] is ${expectedPropValue[i]}, but found ${actualPropValue[i]}`
).to.equal(expectedElement);
expectedElement,
`${context}, property ${expectedProperty.name}[${i}] is ${expectedPropValue[i]}, but found ${actualPropValue[i]}`,
);
}
}
}
else {
expect(
strictEqual(
actualPropValue,
`${context}, comparing property ${expectedProperty.name}`
).to.equal(expectedPropValue);
expectedPropValue,
`${context}, property ${expectedProperty.name} is '${expectedPropValue}', but found '${actualPropValue}'`
);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testing/testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('AssertASTsAreEqual', function() {
const simpleNode2 : Node = new SimpleNode("different node");
expect(() =>
assertASTsAreEqual(simpleNode1, simpleNode2)
).to.throw("expected 'different node' to equal 'node'");
).to.throw("<root>, property name is 'node', but found 'different node'");
});
it("two different node instances of two different types, but with same values must NOT pass", function () {
const node1 : Node = new SimpleNode("node");
Expand Down