Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Jul 9, 2024
1 parent bc3b6fc commit 0ed2dc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tests/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {

export class Box extends Node {
@Children()
@Reflect.metadata("design:arrayElementType", Node)
contents: Node[];

constructor(public name: string, contents: Node[], positionOverride?: Position) {
Expand All @@ -23,9 +22,16 @@ export class Box extends Node {
}

export class Item extends Node {
@Child()
nested?: Item;
constructor(public name: string, positionOverride?: Position) {
super(positionOverride);
}

withNested(nested: Item) {
this.nested = nested;
return this;
}
}

export enum Fibo {
Expand Down
2 changes: 1 addition & 1 deletion tests/traversing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const testCase = new Box(
new Box(
"first",[new Item("1", pos(3, 6, 3, 12))],
pos(2, 3, 4, 3)),
new Item("2", pos(5, 3, 5, 9)),
new Item("2", pos(5, 3, 5, 9)).withNested(new Item("nested")),
new Box("big",[
new Box("small",[
new Item("3", pos(8, 7, 8, 13)),
Expand Down
9 changes: 6 additions & 3 deletions tests/traversing/structurally.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Box} from "../nodes";
import {Box, Item} from "../nodes";
import {expect} from "chai";
import {assignParents} from "../../src";
import {printSequence, testCase} from "../traversing.test";

describe('Traversing structurally', function() {
it("depth-first",
function () {
const result = "root, first, 1, 2, big, small, 3, 4, 5, 6";
const result = "root, first, 1, 2, nested, big, small, 3, 4, 5, 6";
expect(printSequence(testCase.walk())).to.equal(result);
});
it("ancestors",
Expand All @@ -18,8 +18,11 @@ describe('Traversing structurally', function() {
});
it("descendants",
function () {
const result = "first, 1, 2, big, small, 3, 4, 5, 6";
const result = "first, 1, 2, nested, big, small, 3, 4, 5, 6";
expect(printSequence(testCase.walkDescendants())).to.equal(result);
});
it("ancestor of type", () => {
expect((testCase.contents[1] as Item).findAncestorOfType(Box)).to.equal(testCase);
});
});

0 comments on commit 0ed2dc9

Please sign in to comment.