MCPcopy
hub / github.com/benjamn/recast / runTestsForParser

Function runTestsForParser

test/comments.ts:33–836  ·  view source on GitHub ↗
(parserId: any)

Source from the content-addressed store, hash-verified

31});
32
33function runTestsForParser(parserId: any) {
34 if (nodeMajorVersion < 6) {
35 const parser = parserId.split("/").pop();
36 if (parser === "babel" || parser === "flow" || parser === "typescript") {
37 // Babel 7 no longer supports Node 4 and 5.
38 return;
39 }
40 }
41
42 const parserName = parserId.split("/").pop();
43 const parser = require(parserId);
44
45 function pit(message: any, callback: any) {
46 it("[" + parserName + "] " + message, callback);
47 }
48
49 pit("attachment and reprinting", function () {
50 const code = annotated.join(eol);
51 const ast = recast.parse(code, { parser });
52
53 const dup = ast.program.body[0];
54 n.FunctionDeclaration.assert(dup);
55 assert.strictEqual(dup.id.name, "dup");
56
57 // More of a basic sanity test than a comment test.
58 assert.strictEqual(recast.print(ast).code, code);
59 assert.strictEqual(recast.print(ast.program).code, code);
60 assert.strictEqual(recast.print(dup).code, code);
61
62 assert.strictEqual(recast.print(dup.params[0]).code, "/* string */ s");
63
64 assert.strictEqual(recast.print(dup.params[1]).code, "/* int */ n");
65
66 assert.strictEqual(
67 recast.print(dup.body).code,
68 ["/* string */"].concat(annotated.slice(2)).join(eol),
69 );
70
71 const retStmt = dup.body.body[0];
72 n.ReturnStatement.assert(retStmt);
73
74 const indented = annotated.slice(3, 6).join(eol);
75 const flush = fromString(indented).indent(-2);
76
77 assert.strictEqual(recast.print(retStmt).code, flush.toString());
78
79 const join = retStmt.argument;
80 n.CallExpression.assert(join);
81
82 const one = join.callee.object.arguments[0].right;
83 n.Literal.assert(one);
84 assert.strictEqual(one.value, 1);
85 assert.strictEqual(
86 recast.print(one).code,
87 ["/*", " * off-by-*/ 1"].join(eol),
88 );
89 });
90

Callers

nothing calls this directly

Calls 8

fromStringFunction · 0.90
pitFunction · 0.85
joinMethod · 0.80
printMethod · 0.80
concatMethod · 0.80
toStringMethod · 0.65
sliceMethod · 0.45
indentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…