[KT-10614] Fix passing of inline.kt test
This commit is contained in:
@@ -19,23 +19,31 @@ package org.jetbrains.kotlin.js.test.utils;
|
|||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CallCounter extends RecursiveJsVisitor {
|
public class CallCounter extends RecursiveJsVisitor {
|
||||||
|
|
||||||
private final List<JsNameRef> callsNameRefs = new ArrayList<JsNameRef>();
|
private final List<JsNameRef> callsNameRefs = new ArrayList<JsNameRef>();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final Set<String> exceptFunctionNames;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CallCounter countCalls(@NotNull JsNode node) {
|
public static CallCounter countCalls(@NotNull JsNode node) {
|
||||||
CallCounter visitor = new CallCounter();
|
return countCalls(node, Collections.<String>emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static CallCounter countCalls(@NotNull JsNode node, @NotNull Set<String> exceptFunctionNames) {
|
||||||
|
CallCounter visitor = new CallCounter(new HashSet<String>(exceptFunctionNames));
|
||||||
node.accept(visitor);
|
node.accept(visitor);
|
||||||
|
|
||||||
return visitor;
|
return visitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallCounter() {}
|
CallCounter(@NotNull Set<String> exceptFunctionNames) {
|
||||||
|
this.exceptFunctionNames = exceptFunctionNames;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTotalCallsCount() {
|
public int getTotalCallsCount() {
|
||||||
return callsNameRefs.size();
|
return callsNameRefs.size();
|
||||||
@@ -61,7 +69,10 @@ public class CallCounter extends RecursiveJsVisitor {
|
|||||||
JsExpression qualifier = invocation.getQualifier();
|
JsExpression qualifier = invocation.getQualifier();
|
||||||
|
|
||||||
if (qualifier instanceof JsNameRef) {
|
if (qualifier instanceof JsNameRef) {
|
||||||
callsNameRefs.add((JsNameRef) qualifier);
|
JsNameRef nameRef = (JsNameRef) qualifier;
|
||||||
|
if (!exceptFunctionNames.contains(nameRef.getIdent())) {
|
||||||
|
callsNameRefs.add(nameRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,15 @@ public class DirectiveTestUtils {
|
|||||||
private static final DirectiveHandler FUNCTION_CONTAINS_NO_CALLS = new DirectiveHandler("CHECK_CONTAINS_NO_CALLS") {
|
private static final DirectiveHandler FUNCTION_CONTAINS_NO_CALLS = new DirectiveHandler("CHECK_CONTAINS_NO_CALLS") {
|
||||||
@Override
|
@Override
|
||||||
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
||||||
checkFunctionContainsNoCalls(ast, arguments.getFirst());
|
Set<String> exceptNames = new HashSet<String>();
|
||||||
|
String exceptNamesArg = arguments.findNamedArgument("except");
|
||||||
|
if (exceptNamesArg != null) {
|
||||||
|
for (String exceptName : exceptNamesArg.split(";")) {
|
||||||
|
exceptNames.add(exceptName.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFunctionContainsNoCalls(ast, arguments.getFirst(), exceptNames);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -179,9 +187,10 @@ public class DirectiveTestUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkFunctionContainsNoCalls(JsNode node, String functionName) throws Exception {
|
public static void checkFunctionContainsNoCalls(JsNode node, String functionName, @NotNull Set<String> exceptFunctionNames)
|
||||||
|
throws Exception {
|
||||||
JsFunction function = AstSearchUtil.getFunction(node, functionName);
|
JsFunction function = AstSearchUtil.getFunction(node, functionName);
|
||||||
CallCounter counter = CallCounter.countCalls(function);
|
CallCounter counter = CallCounter.countCalls(function, exceptFunctionNames);
|
||||||
int callsCount = counter.getTotalCallsCount();
|
int callsCount = counter.getTotalCallsCount();
|
||||||
|
|
||||||
String errorMessage = functionName + " contains calls";
|
String errorMessage = functionName + " contains calls";
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ package foo
|
|||||||
|
|
||||||
// CHECK_CONTAINS_NO_CALLS: test1
|
// CHECK_CONTAINS_NO_CALLS: test1
|
||||||
// CHECK_CONTAINS_NO_CALLS: test2
|
// CHECK_CONTAINS_NO_CALLS: test2
|
||||||
// CHECK_CONTAINS_NO_CALLS: test3
|
// CHECK_CONTAINS_NO_CALLS: test3 except=slice
|
||||||
|
|
||||||
internal inline fun concat(vararg strings: String): String {
|
internal inline fun concat(vararg strings: String): String {
|
||||||
var result = ""
|
var result = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user