Skip to content

Commit 1d7dadd

Browse files
committed
Turn Visitor into a file and import.
1 parent 0abe081 commit 1d7dadd

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

bin/Visitor.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*!
2+
* Copyright (c) 2024 Digital Bazaar, Inc.
3+
*/
4+
export class Visitor {
5+
/**
6+
* A Visitor traverses nodes in a graph.
7+
*
8+
* @param {object} options - Options for the Class.
9+
* @param {Function<boolean>} options.condition - The condition a node must
10+
* pass to be included in the accumulator.
11+
* @param {Array} options.accumulator - An accumulator to store matching
12+
* nodes in.
13+
* @param {Array<string>} options.props - The props to recur on.
14+
*/
15+
constructor({condition, accumulator, props}) {
16+
this.condition = condition;
17+
this.accumulator = accumulator;
18+
this.props = props;
19+
}
20+
visit({nodes}) {
21+
for(const node of nodes) {
22+
if(this.condition(node)) {
23+
this.accumulator.push(node);
24+
}
25+
for(const prop of this.props) {
26+
if(node[prop]) {
27+
this.visit({nodes: node[prop]});
28+
}
29+
}
30+
}
31+
}
32+
}
33+

bin/handlers.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,7 @@
33
*/
44
import {parse, TextNode} from 'node-html-parser';
55
import {readFile} from 'node:fs/promises';
6-
7-
class Visitor {
8-
constructor({condition, accumulator, props}) {
9-
this.condition = condition;
10-
this.accumulator = accumulator;
11-
this.props = props;
12-
}
13-
visit({nodes}) {
14-
for(const node of nodes) {
15-
if(this.condition(node)) {
16-
this.accumulator.push(node);
17-
}
18-
for(const prop of this.props) {
19-
if(node[prop]) {
20-
this.visit({nodes: node[prop]});
21-
}
22-
}
23-
}
24-
}
25-
}
6+
import {Visitor} from './Visitor.js';
267

278
export async function checkSpecText({specUrl, suiteLog}) {
289
const specUrls = Array.isArray(specUrl) ? specUrl : [specUrl];
@@ -45,13 +26,12 @@ export async function checkSpecText({specUrl, suiteLog}) {
4526
if(suiteLog) {
4627
log = JSON.parse(await readFile(suiteLog));
4728
}
48-
//console.log(accumulator);
4929
if(log) {
5030
testVisitor.visit({nodes: log.suites});
5131
testVisitor.visit({nodes: log.tests});
5232
}
5333
const testTitles = new Set(tests.map(test => test?.title));
54-
const normStatements = new Set(statements);
34+
const normStatements = new Set(statements.map(s => s.text));
5535
console.log(`Test Title Count ${testTitles.size}`);
5636
console.log(`Normative Statement Count ${normStatements.size}`);
5737
}

0 commit comments

Comments
 (0)