JS: test metadata generation
This commit is contained in:
@@ -252,6 +252,12 @@ public class InlineJsTestGenerated extends AbstractInlineJsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("metadataForPublicFunction.kt")
|
||||
public void testMetadataForPublicFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inline/cases/metadataForPublicFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noInlineLambda.kt")
|
||||
public void testNoInlineLambda() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inline/cases/noInlineLambda.kt");
|
||||
|
||||
@@ -16,26 +16,41 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.test.utils;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsFunction;
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.collectNamedFunctions;
|
||||
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.collectJsProperties;
|
||||
|
||||
public class AstSearchUtil {
|
||||
@NotNull
|
||||
public static JsFunction getFunction(@NotNull JsNode searchRoot, String name) {
|
||||
Map<JsName, JsFunction> functions = collectNamedFunctions(searchRoot);
|
||||
JsFunction function = findByIdent(collectNamedFunctions(searchRoot), name);
|
||||
assert function != null: "Function `" + name + "` was not found";
|
||||
return function;
|
||||
}
|
||||
|
||||
for (Map.Entry<JsName, JsFunction> entry : functions.entrySet()) {
|
||||
@NotNull
|
||||
public static JsExpression getProperty(@NotNull JsNode searchRoot, @NotNull String name) {
|
||||
JsExpression property = findByIdent(collectJsProperties(searchRoot), name);
|
||||
assert property != null: "Property `" + name + "` was not found";
|
||||
return property;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends JsExpression> T findByIdent(@NotNull Map<JsName, T> properties, @NotNull String name) {
|
||||
for (Map.Entry<JsName, T> entry : properties.entrySet()) {
|
||||
if (entry.getKey().getIdent().equals(name)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
throw new AssertionError("Function `" + name + "` was not found");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.test.utils;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsFunction;
|
||||
import com.google.dart.compiler.backend.js.ast.JsLabel;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.js.translate.expression.InlineMetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -117,6 +119,26 @@ public class DirectiveTestUtils {
|
||||
}
|
||||
};
|
||||
|
||||
private static final DirectiveHandler HAS_INLINE_METADATA = new DirectiveHandler("CHECK_HAS_INLINE_METADATA") {
|
||||
@Override
|
||||
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
||||
String functionName = arguments.getPositionalArgument(0);
|
||||
JsExpression property = AstSearchUtil.getProperty(ast, functionName);
|
||||
String message = "Inline metadata has not been generated for function " + functionName;
|
||||
assertNotNull(message, InlineMetadata.decompose(property));
|
||||
}
|
||||
};
|
||||
|
||||
private static final DirectiveHandler HAS_NO_INLINE_METADATA = new DirectiveHandler("CHECK_HAS_NO_INLINE_METADATA") {
|
||||
@Override
|
||||
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
||||
String functionName = arguments.getPositionalArgument(0);
|
||||
JsExpression property = AstSearchUtil.getProperty(ast, functionName);
|
||||
String message = "Inline metadata has been generated for not effectively public function " + functionName;
|
||||
assertTrue(message, property instanceof JsFunction);
|
||||
}
|
||||
};
|
||||
|
||||
public static void processDirectives(@NotNull JsNode ast, @NotNull String sourceCode) throws Exception {
|
||||
FUNCTION_CONTAINS_NO_CALLS.process(ast, sourceCode);
|
||||
FUNCTION_NOT_CALLED.process(ast, sourceCode);
|
||||
@@ -124,6 +146,8 @@ public class DirectiveTestUtils {
|
||||
FUNCTION_NOT_CALLED_IN_SCOPE.process(ast, sourceCode);
|
||||
FUNCTIONS_HAVE_SAME_LINES.process(ast, sourceCode);
|
||||
COUNT_LABELS.process(ast, sourceCode);
|
||||
HAS_INLINE_METADATA.process(ast, sourceCode);
|
||||
HAS_NO_INLINE_METADATA.process(ast, sourceCode);
|
||||
}
|
||||
|
||||
public static void checkFunctionContainsNoCalls(JsNode node, String functionName) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user