-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestMoreHelper.java
More file actions
52 lines (46 loc) · 2.09 KB
/
TestMoreHelper.java
File metadata and controls
52 lines (46 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.perlonjava.parser;
import org.perlonjava.astnode.*;
import org.perlonjava.runtime.GlobalVariable;
import org.perlonjava.runtime.NameNormalizer;
import java.util.List;
public class TestMoreHelper {
// Use a macro to emulate Test::More SKIP blocks
static void handleSkipTest(Parser parser, BlockNode block) {
// Locate skip statements
// TODO create skip visitor
for (Node node : block.elements) {
if (node instanceof BinaryOperatorNode op) {
if (!op.operator.equals("(")) {
// Possible if-modifier
if (op.left instanceof BinaryOperatorNode left) {
handleSkipTestInner(parser, left);
}
if (op.right instanceof BinaryOperatorNode right) {
handleSkipTestInner(parser, right);
}
} else {
handleSkipTestInner(parser, op);
}
}
}
}
private static void handleSkipTestInner(Parser parser, BinaryOperatorNode op) {
if (op.operator.equals("(")) {
int index = op.tokenIndex;
if (op.left instanceof OperatorNode sub && sub.operator.equals("&") && sub.operand instanceof IdentifierNode subName && subName.name.equals("skip")) {
// skip() call
// op.right contains the arguments
// Becomes: `skip_internal() && last SKIP`
// But first, test if the subroutine exists
String fullName = NameNormalizer.normalizeVariableName(subName.name + "_internal", parser.ctx.symbolTable.getCurrentPackage());
if (GlobalVariable.existsGlobalCodeRef(fullName)) {
subName.name = fullName;
op.operator = "&&";
op.left = new BinaryOperatorNode("(", op.left, op.right, index);
op.right = new OperatorNode("last",
new ListNode(List.of(new IdentifierNode("SKIP", index)), index), index);
}
}
}
}
}