JS backend: dropped unnecessary intrinsics in StringFIF. Added tests for CharSequence.size, CharSequence.length, CharSequence.length() and CharSequence.isEmpty().
This commit is contained in:
@@ -35,14 +35,14 @@ native public fun String.match(regex : String) : Array<String> = js.noImpl
|
|||||||
|
|
||||||
native public fun String.trim() : String = js.noImpl
|
native public fun String.trim() : String = js.noImpl
|
||||||
|
|
||||||
library
|
native("length")
|
||||||
public val String.size: Int = js.noImpl
|
public val CharSequence.size: Int = js.noImpl
|
||||||
|
|
||||||
library
|
library
|
||||||
public fun String.length(): Int = js.noImpl
|
public fun CharSequence.length(): Int = js.noImpl
|
||||||
|
|
||||||
library
|
library
|
||||||
public fun String.isEmpty(): Boolean = js.noImpl
|
public fun CharSequence.isEmpty(): Boolean = js.noImpl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,6 @@ public final class StringTest extends AbstractExpressionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testExtensionMethods() throws Exception {
|
public void testExtensionMethods() throws Exception {
|
||||||
fooBoxTest();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-4
@@ -27,11 +27,7 @@ public final class StringOperationFIF extends CompositeFIF {
|
|||||||
|
|
||||||
private StringOperationFIF() {
|
private StringOperationFIF() {
|
||||||
add(pattern("jet", "String", "get"), new BuiltInFunctionIntrinsic("charAt"));
|
add(pattern("jet", "String", "get"), new BuiltInFunctionIntrinsic("charAt"));
|
||||||
|
|
||||||
add(pattern("jet", "String", "<get-length>"), LENGTH_PROPERTY_INTRINSIC);
|
|
||||||
add(pattern("js", "<get-size>").receiverExists(), LENGTH_PROPERTY_INTRINSIC);
|
|
||||||
add(pattern("js", "length").receiverExists(), LENGTH_PROPERTY_INTRINSIC);
|
add(pattern("js", "length").receiverExists(), LENGTH_PROPERTY_INTRINSIC);
|
||||||
add(pattern("jet", "CharSequence", "<get-length>"), LENGTH_PROPERTY_INTRINSIC);
|
|
||||||
add(pattern("js", "isEmpty").receiverExists(), IS_EMPTY_INTRINSIC);
|
add(pattern("js", "isEmpty").receiverExists(), IS_EMPTY_INTRINSIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,36 @@
|
|||||||
package foo
|
package foo
|
||||||
|
|
||||||
fun box(): Boolean {
|
val testString = "foobarbaz"
|
||||||
val s = "bar"
|
val testStringSize = 9
|
||||||
return s.size == 3 && s.length() == 3 && s.length == 3 && s.startsWith("b") && s.endsWith("r") && s.contains("a") && !s.isEmpty()
|
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"
|
||||||
|
|||||||
@@ -123,9 +123,6 @@ fun printField(s : String, steps : Int) {
|
|||||||
|
|
||||||
fun <T> Array<T>.toList() : List<T> = this.to(ArrayList<T>())
|
fun <T> Array<T>.toList() : List<T> = this.to(ArrayList<T>())
|
||||||
|
|
||||||
val String?.size : Int
|
|
||||||
get() = if (this != null) this.length else 0;
|
|
||||||
|
|
||||||
fun <T, C: MutableCollection<T>> Array<T>.to(result: C) : C {
|
fun <T, C: MutableCollection<T>> Array<T>.to(result: C) : C {
|
||||||
for (elem in this)
|
for (elem in this)
|
||||||
result.add(elem)
|
result.add(elem)
|
||||||
|
|||||||
Reference in New Issue
Block a user