Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Valdo, havai
  • Loading branch information
zishkaz committed Apr 10, 2023
commit 489e5bd2e0a55778c8516b54c6b468c4880a9388
2 changes: 1 addition & 1 deletion utbot-js/src/main/kotlin/api/JsTestGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class JsTestGenerator(
fuzzedValues: List<UtModel>
): UtExecutionResult {
if (resultData.isError && resultData.rawString == "Timeout") return UtTimeoutException(
TimeoutException(" Timeout in generating test for ${
TimeoutException("Timeout in generating test for ${
execId.parameters
.zip(fuzzedValues)
.joinToString(
Expand Down
27 changes: 21 additions & 6 deletions utbot-js/src/main/kotlin/api/JsUtModelConstructor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import framework.api.js.JsEmptyClassId
import framework.api.js.JsNullModel
import framework.api.js.JsPrimitiveModel
import framework.api.js.JsUndefinedModel
import framework.api.js.util.defaultJsValueModel
import framework.api.js.util.jsErrorClassId
import framework.api.js.util.jsUndefinedClassId
import fuzzer.JsIdProvider
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtExecutableCallModel
import org.utbot.framework.plugin.api.UtModel
Expand All @@ -20,10 +22,6 @@ class JsUtModelConstructor : UtModelConstructorInterface {
@Suppress("NAME_SHADOWING")
override fun construct(value: Any?, classId: ClassId): UtModel {
val classId = classId as JsClassId
when (classId) {
jsUndefinedClassId -> return JsUndefinedModel(classId)
jsErrorClassId -> return UtModel(jsErrorClassId)
}
return when (value) {
null -> JsNullModel(classId)
is Byte,
Expand All @@ -35,12 +33,29 @@ class JsUtModelConstructor : UtModelConstructorInterface {
is Double,
is String,
is Boolean -> JsPrimitiveModel(value)

is List<*> -> {
UtArrayModel(
id = JsIdProvider.createId(),
classId = classId,
stores = buildMap {
putAll(value.indices.zip(value.map {
construct(it, classId)
}))
} as MutableMap<Int, UtModel>,
length = value.size,
constModel = classId.defaultJsValueModel()
)
}
is Map<*, *> -> {
constructObject(classId, value)
}

else -> JsUndefinedModel(classId)
else -> {
when (classId) {
jsErrorClassId -> UtModel(jsErrorClassId)
else -> JsUndefinedModel(classId)
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions utbot-js/src/main/kotlin/framework/api/js/util/JsIdUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ fun JsClassId.defaultJsValueModel(): UtModel = when (this) {
}

val JsClassId.isJsBasic: Boolean
get() = this in jsBasic
get() = this in jsBasic || this.isJsStdStructure

val JsClassId.isExportable: Boolean
get() = !(this.isJsBasic || this == jsErrorClassId || this.isJsStdStructure || this is JsMultipleClassId)
get() = !(this.isJsBasic || this == jsErrorClassId || this is JsMultipleClassId)

val JsClassId.isClass: Boolean
get() = !(this.isJsBasic || this == jsErrorClassId || this.isJsStdStructure || this is JsMultipleClassId)
get() = !(this.isJsBasic || this == jsErrorClassId || this is JsMultipleClassId)

val JsClassId.isUndefined: Boolean
get() = this == jsUndefinedClassId
Expand Down
18 changes: 14 additions & 4 deletions utbot-js/src/main/kotlin/utils/ValueUtil.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package utils

import org.json.JSONException
import org.json.JSONObject
import framework.api.js.JsClassId
import framework.api.js.util.jsBooleanClassId
import framework.api.js.util.jsDoubleClassId
import framework.api.js.util.jsErrorClassId
import framework.api.js.util.jsNumberClassId
import framework.api.js.util.jsStringClassId
import framework.api.js.util.jsUndefinedClassId
import org.json.JSONException
import org.json.JSONObject
import utils.data.ResultData

fun ResultData.toJsAny(returnType: JsClassId = jsUndefinedClassId): Pair<Any?, JsClassId> {
Expand All @@ -17,8 +17,11 @@ fun ResultData.toJsAny(returnType: JsClassId = jsUndefinedClassId): Pair<Any?, J
return when {
this == "true" || this == "false" -> toBoolean() to jsBooleanClassId
this == "null" || this == "undefined" -> null to jsUndefinedClassId
Regex("\\[.*]").matches(this) && returnType.name == "object" ->
makeArray(this) to JsClassId("array", elementClassId = jsUndefinedClassId)
this@toJsAny.isError -> this to jsErrorClassId
returnType == jsStringClassId -> this.replace("\"", "") to jsStringClassId
returnType == jsStringClassId || this@toJsAny.type == jsStringClassId.name ->
this.replace("\"", "") to jsStringClassId
else -> {
if (contains('.')) {
(toDoubleOrNull() ?: toBigDecimal()) to jsDoubleClassId
Expand All @@ -27,7 +30,9 @@ fun ResultData.toJsAny(returnType: JsClassId = jsUndefinedClassId): Pair<Any?, J
?: toBigIntegerOrNull() ?: toDoubleOrNull()
if (value != null) value to jsNumberClassId else {
val obj = makeObject(this)
if (obj != null) obj to returnType else throw IllegalStateException()
if (obj != null) obj to returnType else {
throw IllegalStateException("Could not make js value from $this value with type ${this@toJsAny.type}")
}
}
}
}
Expand Down Expand Up @@ -56,3 +61,8 @@ private fun makeObject(objString: String): Map<String, Any>? {
null
}
}

private fun makeArray(arrString: String): List<Any?> {
val strValues = arrString.replace(Regex("[\\[\\]]"), "").split(",")
return strValues.map { ResultData(it, index = 0).toJsAny(jsUndefinedClassId).first }
}