Adapt ScriptCodegenTests to last changes
Get rid of possibility to configure script definition without template class, therefore all tests now are using default script argument
This commit is contained in:
+2
-3
@@ -1,5 +1,4 @@
|
||||
// expected: rv: sky color is blue
|
||||
// param: what: kotlin.String: sky
|
||||
// param: color: kotlin.String: blue
|
||||
// param: sky blue
|
||||
|
||||
val rv = "$what color is $color"
|
||||
val rv = "${args[0]} color is ${args[1]}"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// param: args: kotlin.Array<kotlin.String>: three little words
|
||||
// param: three little words
|
||||
// expected: rv: little
|
||||
|
||||
val rv = args[1]
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// param: x: kotlin.Int: 10
|
||||
// param: 10
|
||||
|
||||
fun addX(y: Int) = x + y
|
||||
fun addX(y: Int) = java.lang.Integer.parseInt(args[0]) + y
|
||||
|
||||
val rv = addX(3)
|
||||
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
// expected: rv: 19
|
||||
// param: aa: kotlin.Long: 17
|
||||
// param: bb: kotlin.Int: 2
|
||||
// param: 17 2
|
||||
|
||||
val rv = aa + bb
|
||||
val rv = java.lang.Long.parseLong(args[0]) + java.lang.Integer.parseInt(args[1])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider;
|
||||
import org.jetbrains.kotlin.script.ScriptParameter;
|
||||
import org.jetbrains.kotlin.script.StandardScriptDefinition;
|
||||
import org.jetbrains.kotlin.scripts.SimpleParamsTestScriptDefinition;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
@@ -122,54 +124,24 @@ public class CodegenTestFiles {
|
||||
expectedValues.add(Pair.create(fieldName, expectedValue));
|
||||
}
|
||||
|
||||
List<ScriptParameter> scriptParameterTypes = Lists.newArrayList();
|
||||
List<Object> scriptParameterValues = Lists.newArrayList();
|
||||
|
||||
if (file.isScript()) {
|
||||
Pattern scriptParametersPattern = Pattern.compile("param: (\\S+): (\\S+): (\\S.*)");
|
||||
Pattern scriptParametersPattern = Pattern.compile("param: (\\S.*)");
|
||||
Matcher scriptParametersMatcher = scriptParametersPattern.matcher(file.getText());
|
||||
|
||||
while (scriptParametersMatcher.find()) {
|
||||
String name = scriptParametersMatcher.group(1);
|
||||
String type = scriptParametersMatcher.group(2);
|
||||
String valueString = scriptParametersMatcher.group(3);
|
||||
Object value;
|
||||
if (scriptParametersMatcher.find()) {
|
||||
String valueString = scriptParametersMatcher.group(1);
|
||||
String[] values = valueString.split(" ");
|
||||
|
||||
KotlinType jetType;
|
||||
KotlinBuiltIns builtIns = DefaultBuiltIns.getInstance();
|
||||
if (type.equals("kotlin.String")) {
|
||||
value = valueString;
|
||||
jetType = builtIns.getStringType();
|
||||
}
|
||||
else if (type.equals("kotlin.Long")) {
|
||||
value = Long.parseLong(valueString);
|
||||
jetType = builtIns.getLongType();
|
||||
}
|
||||
else if (type.equals("kotlin.Int")) {
|
||||
value = Integer.parseInt(valueString);
|
||||
jetType = builtIns.getIntType();
|
||||
}
|
||||
else if (type.equals("kotlin.Array<kotlin.String>")) {
|
||||
value = valueString.split(" ");
|
||||
jetType = builtIns.getArrayType(Variance.INVARIANT, builtIns.getStringType());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("TODO: " + type);
|
||||
}
|
||||
|
||||
scriptParameterTypes.add(new ScriptParameter(Name.identifier(name), jetType));
|
||||
scriptParameterValues.add(value);
|
||||
scriptParameterValues.add(values);
|
||||
} else {
|
||||
scriptParameterValues.add(ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
KotlinScriptDefinitionProvider definitionProvider = KotlinScriptDefinitionProvider.getInstance(project);
|
||||
definitionProvider.addScriptDefinition(
|
||||
new SimpleParamsTestScriptDefinition(
|
||||
".kts",
|
||||
scriptParameterTypes
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
KotlinScriptDefinitionProvider.getInstance(project).addScriptDefinition(StandardScriptDefinition.INSTANCE);
|
||||
|
||||
return new CodegenTestFiles(Collections.singletonList(file), expectedValues, scriptParameterValues);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user