Skip to content

Commit 0ed2dc9

Browse files
committed
Increase code coverage
1 parent bc3b6fc commit 0ed2dc9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

tests/nodes.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313

1414
export class Box extends Node {
1515
@Children()
16-
@Reflect.metadata("design:arrayElementType", Node)
1716
contents: Node[];
1817

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

2524
export class Item extends Node {
25+
@Child()
26+
nested?: Item;
2627
constructor(public name: string, positionOverride?: Position) {
2728
super(positionOverride);
2829
}
30+
31+
withNested(nested: Item) {
32+
this.nested = nested;
33+
return this;
34+
}
2935
}
3036

3137
export enum Fibo {

tests/traversing.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const testCase = new Box(
2626
new Box(
2727
"first",[new Item("1", pos(3, 6, 3, 12))],
2828
pos(2, 3, 4, 3)),
29-
new Item("2", pos(5, 3, 5, 9)),
29+
new Item("2", pos(5, 3, 5, 9)).withNested(new Item("nested")),
3030
new Box("big",[
3131
new Box("small",[
3232
new Item("3", pos(8, 7, 8, 13)),

tests/traversing/structurally.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {Box} from "../nodes";
1+
import {Box, Item} from "../nodes";
22
import {expect} from "chai";
33
import {assignParents} from "../../src";
44
import {printSequence, testCase} from "../traversing.test";
55

66
describe('Traversing structurally', function() {
77
it("depth-first",
88
function () {
9-
const result = "root, first, 1, 2, big, small, 3, 4, 5, 6";
9+
const result = "root, first, 1, 2, nested, big, small, 3, 4, 5, 6";
1010
expect(printSequence(testCase.walk())).to.equal(result);
1111
});
1212
it("ancestors",
@@ -18,8 +18,11 @@ describe('Traversing structurally', function() {
1818
});
1919
it("descendants",
2020
function () {
21-
const result = "first, 1, 2, big, small, 3, 4, 5, 6";
21+
const result = "first, 1, 2, nested, big, small, 3, 4, 5, 6";
2222
expect(printSequence(testCase.walkDescendants())).to.equal(result);
2323
});
24+
it("ancestor of type", () => {
25+
expect((testCase.contents[1] as Item).findAncestorOfType(Box)).to.equal(testCase);
26+
});
2427
});
2528

0 commit comments

Comments
 (0)