JS backend: fixed String.split for the case when using regexp.
Added(overload) String.split with limit parameter.
This commit is contained in:
@@ -3,15 +3,18 @@ package java.lang
|
||||
import java.io.IOException
|
||||
import js.library
|
||||
|
||||
library("splitString")
|
||||
public fun String.split(regex : String) : Array<String> = js.noImpl
|
||||
|
||||
library("splitString")
|
||||
public fun String.split(regex : String, limit: Int) : Array<String> = js.noImpl
|
||||
|
||||
library
|
||||
open public class Exception(message: String? = null) : Throwable() {}
|
||||
|
||||
library
|
||||
open public class RuntimeException(message: String? = null) : Exception(message) {}
|
||||
|
||||
library("splitString")
|
||||
public fun String.split(regex : String) : Array<String> = js.noImpl
|
||||
|
||||
library
|
||||
public class IllegalArgumentException(message: String? = null) : Exception() {}
|
||||
|
||||
|
||||
@@ -80,4 +80,8 @@ public final class StringTest extends AbstractExpressionTest {
|
||||
assertFalse(filePath + " should not contain toString calls", text.contains("toString"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testStringSplit() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -482,8 +482,8 @@ String.prototype.contains = function (s) {
|
||||
}
|
||||
);
|
||||
|
||||
Kotlin.splitString = function (str, regex) {
|
||||
return str.split(regex);
|
||||
Kotlin.splitString = function (str, regex, limit) {
|
||||
return str.split(new RegExp(regex), limit);
|
||||
};
|
||||
|
||||
Kotlin.nullArray = function (size) {
|
||||
|
||||
Reference in New Issue
Block a user