fix #20 do-while tests for labels, values, else
This commit is contained in:
parent
dacdcd7faa
commit
7cc80e2433
@ -1750,8 +1750,9 @@ class ScriptTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testThrowExisting()= runTest {
|
fun testThrowExisting() = runTest {
|
||||||
eval("""
|
eval(
|
||||||
|
"""
|
||||||
val x = IllegalArgumentException("test")
|
val x = IllegalArgumentException("test")
|
||||||
assert( x is Exception )
|
assert( x is Exception )
|
||||||
|
|
||||||
@ -1773,12 +1774,14 @@ class ScriptTest {
|
|||||||
}
|
}
|
||||||
assertEquals(3, t)
|
assertEquals(3, t)
|
||||||
assert(finallyCaught)
|
assert(finallyCaught)
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCatchShort1()= runTest {
|
fun testCatchShort1() = runTest {
|
||||||
eval("""
|
eval(
|
||||||
|
"""
|
||||||
val x = IllegalArgumentException("test")
|
val x = IllegalArgumentException("test")
|
||||||
var t = 0
|
var t = 0
|
||||||
var finallyCaught = false
|
var finallyCaught = false
|
||||||
@ -1795,12 +1798,14 @@ class ScriptTest {
|
|||||||
}
|
}
|
||||||
assertEquals(31, t)
|
assertEquals(31, t)
|
||||||
assert(finallyCaught)
|
assert(finallyCaught)
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCatchShort2()= runTest {
|
fun testCatchShort2() = runTest {
|
||||||
eval("""
|
eval(
|
||||||
|
"""
|
||||||
val x = IllegalArgumentException("test")
|
val x = IllegalArgumentException("test")
|
||||||
var caught = null
|
var caught = null
|
||||||
try {
|
try {
|
||||||
@ -1810,12 +1815,14 @@ class ScriptTest {
|
|||||||
caught = it
|
caught = it
|
||||||
}
|
}
|
||||||
assert( caught is IllegalArgumentException )
|
assert( caught is IllegalArgumentException )
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAccessEHData() = runTest {
|
fun testAccessEHData() = runTest {
|
||||||
eval("""
|
eval(
|
||||||
|
"""
|
||||||
val x = IllegalArgumentException("test")
|
val x = IllegalArgumentException("test")
|
||||||
val m = try {
|
val m = try {
|
||||||
throw x
|
throw x
|
||||||
@ -1830,7 +1837,8 @@ class ScriptTest {
|
|||||||
}
|
}
|
||||||
println(m)
|
println(m)
|
||||||
assert( m == "test" )
|
assert( m == "test" )
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1849,9 +1857,11 @@ class ScriptTest {
|
|||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
c.eval("""
|
c.eval(
|
||||||
|
"""
|
||||||
assertEquals("freed", resource)
|
assertEquals("freed", resource)
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1860,7 +1870,8 @@ class ScriptTest {
|
|||||||
c.addFn("callThrow") {
|
c.addFn("callThrow") {
|
||||||
raiseArgumentError("fromKotlin")
|
raiseArgumentError("fromKotlin")
|
||||||
}
|
}
|
||||||
c.eval("""
|
c.eval(
|
||||||
|
"""
|
||||||
val result = try {
|
val result = try {
|
||||||
callThrow()
|
callThrow()
|
||||||
"fail"
|
"fail"
|
||||||
@ -1873,12 +1884,14 @@ class ScriptTest {
|
|||||||
"ok"
|
"ok"
|
||||||
}
|
}
|
||||||
assertEquals(result, "ok")
|
assertEquals(result, "ok")
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testReturnValue1() = runTest {
|
fun testReturnValue1() = runTest {
|
||||||
val r = eval("""
|
val r = eval(
|
||||||
|
"""
|
||||||
class Point(x,y) {
|
class Point(x,y) {
|
||||||
println("1")
|
println("1")
|
||||||
fun length() { sqrt(d2()) }
|
fun length() { sqrt(d2()) }
|
||||||
@ -1891,8 +1904,79 @@ class ScriptTest {
|
|||||||
// assertEquals( 5, p.length() )
|
// assertEquals( 5, p.length() )
|
||||||
// assertThrows { p.d2() }
|
// assertThrows { p.d2() }
|
||||||
"111"
|
"111"
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
assertEquals("111", r.toString())
|
assertEquals("111", r.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun doWhileValuesTest() = runTest {
|
||||||
|
eval(
|
||||||
|
"""
|
||||||
|
var count = 0
|
||||||
|
val result = do {
|
||||||
|
count++
|
||||||
|
if( count < 10 )
|
||||||
|
continue
|
||||||
|
if( count % 2 == 1 )
|
||||||
|
break "found "+count
|
||||||
|
} while(count < 100)
|
||||||
|
else "no"
|
||||||
|
assertEquals("found 11", result)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
eval(
|
||||||
|
"""
|
||||||
|
var count = 0
|
||||||
|
val result = do {
|
||||||
|
count++
|
||||||
|
if( count < 10 )
|
||||||
|
continue
|
||||||
|
if( count % 2 == 1 )
|
||||||
|
break "found "+count
|
||||||
|
} while(count < 5)
|
||||||
|
else "no"
|
||||||
|
assertEquals("no", result)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
eval(
|
||||||
|
"""
|
||||||
|
var count = 0
|
||||||
|
val result = do {
|
||||||
|
count++
|
||||||
|
if( count % 2 == 3 )
|
||||||
|
break "found "+count
|
||||||
|
"proc "+count
|
||||||
|
} while(count < 5)
|
||||||
|
assertEquals("proc 5", result)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun doWhileValuesLabelTest() = runTest {
|
||||||
|
eval(
|
||||||
|
"""
|
||||||
|
var count = 0
|
||||||
|
var count2 = 0
|
||||||
|
var count3 = 0
|
||||||
|
val result = outer@ do {
|
||||||
|
count2++
|
||||||
|
count = 0
|
||||||
|
do {
|
||||||
|
count++
|
||||||
|
if( count < 10 || count2 < 5 ) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if( count % 2 == 1 )
|
||||||
|
break@outer "found "+count + "/" + count2
|
||||||
|
} while(count < 14)
|
||||||
|
count3++
|
||||||
|
} while( count2 < 100 )
|
||||||
|
else "no"
|
||||||
|
assertEquals("found 11/5", result)
|
||||||
|
assertEquals( 4, count3)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user