Fix EvaluateTests for strings
This commit is contained in:
+2
-1
@@ -517,7 +517,8 @@ private fun createStringConstant(value: CompileTimeConstant<*>?): StringValue? {
|
||||
is IntValue, is ByteValue, is ShortValue, is LongValue,
|
||||
is CharValue,
|
||||
is DoubleValue, is FloatValue,
|
||||
is BooleanValue -> StringValue(value.getValue().toString())
|
||||
is BooleanValue,
|
||||
is NullValue -> StringValue(value.getValue().toString())
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,29 +4,29 @@ enum class MyEnum {
|
||||
A
|
||||
}
|
||||
|
||||
// val prop1: "2"
|
||||
// val prop1: \"2\"
|
||||
val prop1 = "${1 + 1}"
|
||||
|
||||
// val prop2: null
|
||||
val prop2 = "myEnum=${MyEnum.A}"
|
||||
|
||||
// val prop3: "1"
|
||||
// val prop3: \"1\"
|
||||
val prop3 = "${1}"
|
||||
|
||||
// val prop4: null
|
||||
// val prop4: \"null\"
|
||||
val prop4 = "${null}"
|
||||
|
||||
// val prop5: "1.0"
|
||||
// val prop5: \"1.0\"
|
||||
val prop5 = "${1.toFloat()}"
|
||||
|
||||
// val prop6: "1.0"
|
||||
// val prop6: \"1.0\"
|
||||
val prop6 = "${1.0}"
|
||||
|
||||
// val prop7: null
|
||||
val prop7 = "${javaClass<Int>()}"
|
||||
|
||||
// val prop8: "a1.0"
|
||||
// val prop8: \"a1.0\"
|
||||
val prop8 = "a${1.toDouble()}"
|
||||
|
||||
// val prop9: "ab"
|
||||
// val prop9: \"ab\"
|
||||
val prop9 = "a" + "b"
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue
|
||||
|
||||
abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResolveTest() {
|
||||
|
||||
@@ -39,7 +40,12 @@ abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResol
|
||||
doTest(path) {
|
||||
property, context ->
|
||||
val compileTimeConstant = context.get(BindingContext.COMPILE_TIME_VALUE, property.getInitializer())
|
||||
compileTimeConstant.toString()
|
||||
if (compileTimeConstant is StringValue) {
|
||||
"\\\"${compileTimeConstant.getValue()}\\\""
|
||||
}
|
||||
else {
|
||||
compileTimeConstant.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,22 +65,23 @@ abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResol
|
||||
|
||||
val propertiesForTest = getObjectsToTest(fileText)
|
||||
|
||||
val expectedActual = hashMapOf<String, String>()
|
||||
val expectedActual = arrayListOf<Pair<String, String>>()
|
||||
|
||||
for (propertyName in propertiesForTest) {
|
||||
val expectedProperyPrefix = "// val ${propertyName}: "
|
||||
val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, expectedProperyPrefix)
|
||||
assertNotNull(expected, "Failed to find expected directive: $expectedProperyPrefix")
|
||||
val expectedPropertyPrefix = "// val ${propertyName}: "
|
||||
val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, expectedPropertyPrefix)
|
||||
assertNotNull(expected, "Failed to find expected directive: $expectedPropertyPrefix")
|
||||
|
||||
val property = AbstractAnnotationDescriptorResolveTest.getPropertyDescriptor(packageView, propertyName)
|
||||
val jetProperty = BindingContextUtils.descriptorToDeclaration(context!!, property) as JetProperty
|
||||
|
||||
val testedObject = getValueToTest(jetProperty, context!!)
|
||||
expectedActual[expectedProperyPrefix + expected!!] = expectedProperyPrefix + StringUtil.unquoteString(testedObject)
|
||||
expectedActual.add(expectedPropertyPrefix + expected!! to expectedPropertyPrefix + testedObject)
|
||||
}
|
||||
|
||||
var actualFileText = fileText
|
||||
for ((expected, actual) in expectedActual) {
|
||||
assert(actualFileText.contains(expected), "File text should contains $expected")
|
||||
actualFileText = actualFileText.replace(expected, actual)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user