JS backend: testFiles -> testData
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package foo
|
||||
|
||||
val testString = "foobarbaz"
|
||||
val testStringSize = 9
|
||||
val emptyString = ""
|
||||
val startsWithParam = "foo"
|
||||
val endsWithParam = "az"
|
||||
val containsParam = "ar"
|
||||
|
||||
fun assertEquals(actual: Any, expected: Any, s: String, whatTested: String) =
|
||||
if (expected != actual) "String.$whatTested fails on \"$s\", expected: $expected, actual: $actual" else null
|
||||
|
||||
fun assertEquals(actual: Any, expected: Any, s: CharSequence, whatTested: CharSequence) =
|
||||
if (expected != actual) "CharSequence.$whatTested fails on \"$s\", expected: $expected, actual: $actual" else null
|
||||
|
||||
fun testString(s: String, expectedSize: Int): String? =
|
||||
assertEquals(s.size, expectedSize, s, "size") ?:
|
||||
assertEquals(s.length(), expectedSize, s, "length()") ?:
|
||||
assertEquals(s.length, expectedSize, s, "length") ?:
|
||||
assertEquals(s.isEmpty(), expectedSize == 0, s, "isEmpty()") ?:
|
||||
assertEquals(s.startsWith(startsWithParam), expectedSize != 0, s, "startsWith(\"$startsWithParam\")") ?:
|
||||
assertEquals(s.endsWith(endsWithParam), expectedSize != 0, s, "endsWith(\"$endsWithParam\")") ?:
|
||||
assertEquals(s.contains(containsParam), expectedSize != 0, s, "contains(\"$containsParam\")")
|
||||
|
||||
fun testCharSequence(s: CharSequence, expectedSize: Int): String? =
|
||||
assertEquals(s.size, expectedSize, s, "size") ?:
|
||||
assertEquals(s.length(), expectedSize, s, "length()") ?:
|
||||
assertEquals(s.length, expectedSize, s, "length") ?:
|
||||
assertEquals(s.isEmpty(), expectedSize == 0, s, "isEmpty()")
|
||||
|
||||
fun box(): String =
|
||||
testString(testString, testStringSize) ?:
|
||||
testString(emptyString, 0) ?:
|
||||
testCharSequence(testString, testStringSize) ?:
|
||||
testCharSequence(emptyString, 0) ?:
|
||||
"OK"
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var number = 3
|
||||
return ("my age is $number");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if ("${3}" != "3") return false
|
||||
return "${3}" == "3"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
class A() {
|
||||
override fun toString(): String {
|
||||
i++
|
||||
return "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A()
|
||||
val s = "$a == $a"
|
||||
return s == "bar == bar" && i == 2
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var right = 2
|
||||
var left = 3
|
||||
return ("left = $left\nright = $right\nsum = ${left + right}\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val number = 3
|
||||
val s1 = "${number - 1}${number}"
|
||||
val s2 = "${5}${4}"
|
||||
return "${s1}${s2}"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class A(var i: Int) {
|
||||
override fun toString() = "a$i"
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var p = A(2);
|
||||
var n = A(1);
|
||||
if ("$p$n" != "a2a1") {
|
||||
return false;
|
||||
}
|
||||
if ("${A(10)}" != "a10") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
val a = "bar";
|
||||
var b = "foo";
|
||||
b = a;
|
||||
return (b == "bar");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
val a = "String";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var name = "Hello"
|
||||
return ("o${name}o");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
val t1: Any = "3"
|
||||
val t2: Any = 3
|
||||
val t3: Any = "4"
|
||||
val t4: Any = 4
|
||||
if (t3 == t4) return false
|
||||
return t1 != t2
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package foo
|
||||
|
||||
// todo drop
|
||||
class Pair<F, S>(val first: F, val second: S)
|
||||
fun <F, S> F.to(second: S): Pair<F, S> = Pair(this, second)
|
||||
|
||||
fun box(): String {
|
||||
val testInput = "test data\t1foo 2 bar"
|
||||
val tests = array(
|
||||
" " to array("test", "data\t1foo", "", "2", "bar"),
|
||||
"\\s+" to array("test", "data", "1foo", "2", "bar"),
|
||||
"[sd]" to array("te", "t ", "ata\t1foo 2 bar"),
|
||||
"[\\d]" to array("test data\t", "foo ", " bar")
|
||||
)
|
||||
|
||||
for (test in tests) {
|
||||
val regexp = test.first
|
||||
val expected = test.second
|
||||
val result = testInput.split(regexp)
|
||||
|
||||
if (result != expected) 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.split(regexp, limit)
|
||||
|
||||
if (result != expected) return "Wrong result for '$regexp' -- Expected: $expected | Actual: $result"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user