JS: move expressions test to box tests

This commit is contained in:
Alexey Andreev
2016-08-26 19:32:17 +03:00
parent 2bf0199959
commit b159049be8
314 changed files with 2380 additions and 2185 deletions
@@ -0,0 +1,41 @@
package foo
class UserException() : RuntimeException()
fun bar(e: Exception): String {
var s: String = ""
var exceptionObject: Exception? = null
try {
throw e
}
catch (e: UserException) {
s = "UserException"
exceptionObject = e
}
catch (e: IllegalArgumentException) {
s = "IllegalArgumentException"
exceptionObject = e
}
catch (e: IllegalStateException) {
s = "IllegalStateException"
exceptionObject = e
}
catch (e: Exception) {
s = "Exception"
exceptionObject = e
}
assertEquals(e, exceptionObject, "e == exceptionObject")
return s
}
fun box(): String {
assertEquals("UserException", bar(UserException()))
assertEquals("IllegalArgumentException", bar(IllegalArgumentException()))
assertEquals("IllegalStateException", bar(IllegalStateException()))
assertEquals("Exception", bar(Exception()))
return "OK"
}
@@ -0,0 +1,23 @@
package foo
fun catchSomeExceptions(e: Exception) {
try {
throw e
}
catch (e: NullPointerException) { }
catch(e: IllegalArgumentException) { }
fail("should not reach this point")
}
fun box(): String {
try {
catchSomeExceptions(RuntimeException())
} catch(e: RuntimeException) {
return "OK"
}
return "Not OK"
}
@@ -0,0 +1,24 @@
package foo
open class Ex: Exception()
class Ex1: Ex()
fun box(): String {
var s: String = ""
try {
throw Ex1()
}
catch (e: Ex) {
s = "Ex"
}
catch (e: Ex1) {
throw Exception("Control flow cannot get here")
}
assertEquals("Ex", s)
return "OK"
}
@@ -0,0 +1,20 @@
package foo
fun box(): String {
var res = try { 10 } catch(e: Exception) { 20 }
assertEquals(10, res)
res = try { 10 } catch(e: Exception) { 20 } finally { 80 }
assertEquals(10, res)
res = try { 10; throw RuntimeException() } catch(e: Exception) { 20 }
assertEquals(20, res)
res = try { 10; throw RuntimeException() } catch(e: Exception) { 20 } finally { 100 }
assertEquals(20, res)
res = 50 + try { 10 } catch(e: Exception) { 20 }
assertEquals(60, res)
return "OK"
}
@@ -0,0 +1,57 @@
package foo
fun box(): String {
var s: String = ""
try {
throw Exception("Exception")
} catch (e: Throwable) {
s = "Throwable:" + e.message!!
}
assertEquals("Throwable:Exception", s)
s = ""
try {
throw Exception("Exception")
} catch (e: Exception) {
s = "Exception:" + e.message!!
}
assertEquals("Exception:Exception", s)
s = ""
try {
throw RuntimeException("RuntimeException")
} catch (e: Exception) {
s = "Exception:" + e.message!!
}
assertEquals("Exception:RuntimeException", s)
s = ""
try {
throw NullPointerException("NullPointerException")
} catch (e: Exception) {
s = "Exception:" + e.message!!
}
assertEquals("Exception:NullPointerException", s)
s = ""
try {
throw IndexOutOfBoundsException("IndexOutOfBoundsException")
} catch (e: NullPointerException) {
s = "NullPointerException:" + e.message!!
} catch (e: RuntimeException) {
s = "RuntimeException:" + e.message!!
} catch (e: Exception) {
s = "Exception:" + e.message!!
}
assertEquals("RuntimeException:IndexOutOfBoundsException", s)
try {
throw RuntimeException()
} catch (e: Exception) {
assertEquals(null, e.message)
}
return "OK"
}
@@ -0,0 +1,15 @@
package foo
fun box(): String {
var s: String = ""
try {
throw Exception()
} catch (e: Throwable) {
s = "Throwable"
}
assertEquals("Throwable", s)
return "OK"
}
@@ -0,0 +1,29 @@
package foo
fun bar(e: Exception): String {
var s: String = ""
var exceptionObject: Exception? = null
try {
throw e
}
catch (e1: IllegalArgumentException) {
s = "IllegalArgumentException"
exceptionObject = e1
}
catch (e2: Exception) {
s = "Exception"
exceptionObject = e
}
assertEquals(e, exceptionObject, "e == exceptionObject")
return s
}
fun box(): String {
assertEquals("IllegalArgumentException", bar(IllegalArgumentException()))
assertEquals("Exception", bar(Exception()))
return "OK"
}