This commit is contained in:
kunfei 2023-03-24 23:50:01 +08:00
parent abea6b092b
commit 218e56bf98
2 changed files with 18 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package io.legado.app
import com.script.SimpleBindings
import com.script.rhino.RhinoScriptEngine
import org.junit.Assert.assertEquals
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
@ -13,4 +16,18 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
@Test
fun jsTest() {
val scriptEngine = RhinoScriptEngine()
val map = hashMapOf("id" to "3242532321")
map["id"] = "12314123"
val bindings = SimpleBindings()
bindings["result"] = map
val js = "$=result;id=$.id;id"
val result = scriptEngine.eval(js, bindings)?.toString()
assertEquals("12314123", result)
}
}

View File

@ -35,5 +35,5 @@ android {
}
dependencies {
api(fileTree(dir: 'lib', include: ['rhino-1.7.14-2.jar']))
api(fileTree(dir: 'lib', include: ['rhino-1.7.13-2.jar']))
}