Adjust JS backend to CharSequence.length transformation

This commit is contained in:
Denis Zharkov
2015-10-11 21:48:21 +03:00
committed by Mikhail Glukhikh
parent 1305d9755a
commit cb562e7ea5
2 changed files with 5 additions and 7 deletions
@@ -26,10 +26,8 @@ public final class StringOperationFIF extends CompositeFIF {
public static final FunctionIntrinsicFactory INSTANCE = new StringOperationFIF(); public static final FunctionIntrinsicFactory INSTANCE = new StringOperationFIF();
private StringOperationFIF() { private StringOperationFIF() {
add(pattern("kotlin", "String", "get"), new BuiltInFunctionIntrinsic("charAt"));
// This intrinsic is needed because charAt is a public function taking one parameter and thus its name would be mangled otherwise
add(pattern("kotlin", "CharSequence", "get").checkOverridden(), new BuiltInFunctionIntrinsic("charAt")); add(pattern("kotlin", "CharSequence", "get").checkOverridden(), new BuiltInFunctionIntrinsic("charAt"));
add(pattern("kotlin", "CharSequence", "length").checkOverridden(), LENGTH_PROPERTY_INTRINSIC); add(pattern("kotlin", "CharSequence", "<get-length>").checkOverridden(), LENGTH_PROPERTY_INTRINSIC);
add(pattern("kotlin", "CharSequence", "subSequence").checkOverridden(), new BuiltInFunctionIntrinsic("substring")); add(pattern("kotlin", "CharSequence", "subSequence").checkOverridden(), new BuiltInFunctionIntrinsic("substring"));
} }
} }
+4 -4
View File
@@ -345,7 +345,7 @@ class StringTest {
val s = "sample" val s = "sample"
assertEquals(listOf(s.indices), s.rangesDelimitedBy("-").toList()) assertEquals(listOf(s.indices), s.rangesDelimitedBy("-").toList())
assertEquals(listOf(s.indices), s.rangesDelimitedBy("-", startIndex = -1).toList()) assertEquals(listOf(s.indices), s.rangesDelimitedBy("-", startIndex = -1).toList())
assertTrue(s.rangesDelimitedBy("-", startIndex = s.length()).single().isEmpty()) assertTrue(s.rangesDelimitedBy("-", startIndex = s.length).single().isEmpty())
} }
*/ */
@@ -470,7 +470,7 @@ class StringTest {
assertEquals(4, string.lastIndexOf('e')) assertEquals(4, string.lastIndexOf('e'))
assertEquals(2, string.lastIndexOf('e', 3)) assertEquals(2, string.lastIndexOf('e', 3))
for (startIndex in -1..string.length()+1) { for (startIndex in -1..string.length+1) {
assertEquals(string.indexOfAny(charArrayOf('e'), startIndex), string.indexOf('e', startIndex)) assertEquals(string.indexOfAny(charArrayOf('e'), startIndex), string.indexOf('e', startIndex))
assertEquals(string.lastIndexOfAny(charArrayOf('e'), startIndex), string.lastIndexOf('e', startIndex)) assertEquals(string.lastIndexOfAny(charArrayOf('e'), startIndex), string.lastIndexOf('e', startIndex))
} }
@@ -487,7 +487,7 @@ class StringTest {
assertEquals(2, string.lastIndexOf('e', 3, ignoreCase = true)) assertEquals(2, string.lastIndexOf('e', 3, ignoreCase = true))
for (startIndex in -1..string.length()+1){ for (startIndex in -1..string.length+1){
assertEquals(string.indexOfAny(charArrayOf('e'), startIndex, ignoreCase = true), string.indexOf('E', startIndex, ignoreCase = true)) assertEquals(string.indexOfAny(charArrayOf('e'), startIndex, ignoreCase = true), string.indexOf('E', startIndex, ignoreCase = true))
assertEquals(string.lastIndexOfAny(charArrayOf('E'), startIndex, ignoreCase = true), string.lastIndexOf('e', startIndex, ignoreCase = true)) assertEquals(string.lastIndexOfAny(charArrayOf('E'), startIndex, ignoreCase = true), string.lastIndexOf('e', startIndex, ignoreCase = true))
} }
@@ -664,7 +664,7 @@ ${" "}
""".trimIndent() """.trimIndent()
assertEquals(23, deindented.lines().size()) assertEquals(23, deindented.lines().size())
val indents = deindented.lines().map { "^\\s*".toRegex().match(it)!!.value.length() } val indents = deindented.lines().map { "^\\s*".toRegex().match(it)!!.value.size }
assertEquals(0, indents.min()) assertEquals(0, indents.min())
assertEquals(42, indents.max()) assertEquals(42, indents.max())
assertEquals(1, deindented.lines().count { it.isEmpty() }) assertEquals(1, deindented.lines().count { it.isEmpty() })