1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const chai_1 = require("chai");
|
14 | const node_visitor_1 = require("../shady-css/node-visitor");
|
15 | class TestNodeVisitor extends node_visitor_1.NodeVisitor {
|
16 | constructor() {
|
17 | super();
|
18 | this.aCallCount = 0;
|
19 | this.bCallCount = 0;
|
20 | }
|
21 | a(a) {
|
22 | this.aCallCount++;
|
23 | if (a.callback) {
|
24 | a.callback();
|
25 | }
|
26 | return 'a';
|
27 | }
|
28 | b(b) {
|
29 | this.bCallCount++;
|
30 | if (b.child) {
|
31 | this.visit(b.child);
|
32 | }
|
33 | return 'b';
|
34 | }
|
35 | }
|
36 | describe('NodeVisitor', () => {
|
37 | let nodeVisitor;
|
38 | beforeEach(function () {
|
39 | nodeVisitor = new TestNodeVisitor();
|
40 | });
|
41 | it('visits nodes based on their type property', () => {
|
42 | nodeVisitor.visit({ type: 'a' });
|
43 | chai_1.expect(nodeVisitor.aCallCount).to.be.eql(1);
|
44 | chai_1.expect(nodeVisitor.bCallCount).to.be.eql(0);
|
45 | nodeVisitor.visit({ type: 'b' });
|
46 | chai_1.expect(nodeVisitor.aCallCount).to.be.eql(1);
|
47 | chai_1.expect(nodeVisitor.bCallCount).to.be.eql(1);
|
48 | });
|
49 | it('reveals the path of the recursive visitation of nodes', () => {
|
50 | const a1 = {
|
51 | type: 'a',
|
52 | callback: function () {
|
53 | chai_1.expect(nodeVisitor.path).to.be.eql([a1]);
|
54 | }
|
55 | };
|
56 | const a2 = {
|
57 | type: 'a',
|
58 | callback: function () {
|
59 | chai_1.expect(nodeVisitor.path).to.be.eql([b, a2]);
|
60 | }
|
61 | };
|
62 | const b = { type: 'b', child: a2 };
|
63 | nodeVisitor.visit(a1);
|
64 | chai_1.expect(nodeVisitor.aCallCount).to.be.eql(1);
|
65 | nodeVisitor.visit(b);
|
66 | chai_1.expect(nodeVisitor.aCallCount).to.be.eql(2);
|
67 | chai_1.expect(nodeVisitor.bCallCount).to.be.eql(1);
|
68 | });
|
69 | });
|
70 |
|
\ | No newline at end of file |