JS: move expressions test to box tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package foo
|
||||
|
||||
val testString = "foobarbaz"
|
||||
val testStringSize = 9
|
||||
val testIndexOfB = 3
|
||||
val emptyString = ""
|
||||
val startsWithParam = "foo"
|
||||
val endsWithParam = "az"
|
||||
val containsParam = "ar"
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any, s: CharSequence, type: String, whatTested: String) {
|
||||
assertEquals(expected, actual, "$type.$whatTested fails on \"$s\"")
|
||||
}
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any, s: String, whatTested: String) {
|
||||
assertEquals(expected, actual, s, "String", whatTested)
|
||||
}
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any, s: CharSequence, whatTested: String) {
|
||||
assertEquals(expected, actual, s, "CharSequence", whatTested)
|
||||
}
|
||||
|
||||
fun testString(s: String, expectedSize: Int, indexOfB: Int) {
|
||||
assertEquals(expectedSize, s.size, s, "size")
|
||||
assertEquals(expectedSize, s.length, s, "length")
|
||||
assertEquals(expectedSize == 0, s.isEmpty(), s, "isEmpty()")
|
||||
assertEquals(expectedSize != 0, s.startsWith(startsWithParam), s, "startsWith(\"$startsWithParam\")")
|
||||
assertEquals(expectedSize != 0, s.endsWith(endsWithParam), s, "endsWith(\"$endsWithParam\")")
|
||||
assertEquals(expectedSize != 0, s.contains(containsParam), s, "contains(\"$containsParam\")")
|
||||
assertEquals(indexOfB, s.indexOf("bar"), s, "indexOf(\"bar\")")
|
||||
assertEquals(-1, s.indexOf("Go"), s, "indexOf(\"Go\")")
|
||||
assertEquals(indexOfB, s.indexOf("b"), s, "indexOf(\"b\")")
|
||||
assertEquals(-1, s.indexOf("G"), s, "indexOf(\"G\")")
|
||||
}
|
||||
|
||||
fun testCharSequence(s: CharSequence, expectedSize: Int) {
|
||||
assertEquals(expectedSize, s.size, s, "size")
|
||||
assertEquals(expectedSize, s.length, s, "length")
|
||||
assertEquals(expectedSize == 0, s.isEmpty(), s, "isEmpty()")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testString(testString, testStringSize, testIndexOfB)
|
||||
testString(emptyString, 0, -1)
|
||||
testCharSequence(testString, testStringSize)
|
||||
testCharSequence(emptyString, 0)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=toString
|
||||
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var number = 3
|
||||
assertEquals("my age is 3", "my age is $number")
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
if ("${3}" != "3") return "fail1"
|
||||
return if ("${3}" == "3") "OK" else "fail2"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
class A() {
|
||||
override fun toString(): String {
|
||||
i++
|
||||
return "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val s = "$a == $a"
|
||||
return if (s == "bar == bar" && i == 2) "OK" else "fail"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=toString
|
||||
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var right = 2
|
||||
var left = 3
|
||||
assertEquals("left = 3\nright = 2\nsum = 5\n", "left = $left\nright = $right\nsum = ${left + right}\n");
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// KT-2901 nullable type in string template
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var a: Int? = null
|
||||
|
||||
assertEquals("a: null", "a: ${a}")
|
||||
|
||||
a = 10
|
||||
assertEquals("a: 10", "a: ${a}")
|
||||
|
||||
var s: String? = null
|
||||
assertEquals("s: null", "s: $s")
|
||||
|
||||
s = "test"
|
||||
assertEquals("s: test", "s: $s")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val number = 3
|
||||
val s1 = "${number - 1}${number}"
|
||||
val s2 = "${5}${4}"
|
||||
assertEquals("2354", "${s1}${s2}")
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class A(var i: Int) {
|
||||
override fun toString() = "a$i"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var p = A(2);
|
||||
var n = A(1);
|
||||
if ("$p$n" != "a2a1") {
|
||||
return "fail1"
|
||||
}
|
||||
if ("${A(10)}" != "a10") {
|
||||
return "fail2"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val a = "bar";
|
||||
var b = "foo";
|
||||
b = a;
|
||||
return if (b == "bar") "OK" else "fail"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val a = "String";
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=toString
|
||||
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var name = "Hello"
|
||||
assertEquals("oHelloo", "o${name}o")
|
||||
return "OK";
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val t1: Any = "3"
|
||||
val t2: Any = 3
|
||||
val t3: Any = "4"
|
||||
val t4: Any = 4
|
||||
if (t3 == t4) return "fail"
|
||||
return if (t1 != t2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val testInput = "test data\t1foo 2 bar"
|
||||
val tests = arrayOf(
|
||||
" " to arrayOf("test", "data\t1foo", "", "2", "bar"),
|
||||
"\\s+" to arrayOf("test", "data", "1foo", "2", "bar"),
|
||||
"[sd]" to arrayOf("te", "t ", "ata\t1foo 2 bar"),
|
||||
"[\\d]" to arrayOf("test data\t", "foo ", " bar")
|
||||
)
|
||||
|
||||
for (test in tests) {
|
||||
val regexp = test.first
|
||||
val expected = test.second
|
||||
val result = testInput.splitWithRegex(regexp)
|
||||
|
||||
if (result.asList() != expected.asList()) return "Wrong result for '$regexp' -- Expected: $expected | Actual: $result"
|
||||
}
|
||||
|
||||
for (test in tests) {
|
||||
val regexp = test.first
|
||||
val limit = 2
|
||||
val expected = Array(limit) { test.second[it] }
|
||||
val result = testInput.splitWithRegex(regexp, limit)
|
||||
|
||||
if (result.asList() != expected.asList()) return "Wrong result for '$regexp' -- Expected: $expected | Actual: $result"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val kotlin: String = "kotlin"
|
||||
|
||||
if (kotlin.subSequence(0, kotlin.length) != kotlin) return "Fail 0"
|
||||
|
||||
val kot: CharSequence = kotlin.subSequence(0, 3)
|
||||
if (kot.toString() != "kot") return "Fail 1: $kot"
|
||||
|
||||
val tlin = (kotlin as CharSequence).subSequence(2, 6)
|
||||
if (tlin.toString() != "tlin") return "Fail 2: $tlin"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user