Fix js-stdlib compilation and tests.

This commit is contained in:
Ilya Gorbunov
2015-03-20 16:30:53 +03:00
parent 4c58f4ec20
commit 5b2a5c78ca
4 changed files with 26 additions and 5 deletions
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.js
// actually \s is enough to match all whitespace, but \xA0 added because of different regexp behavior of Rhino used in Selenium tests
public fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]")
+1 -1
View File
@@ -37,7 +37,7 @@ public trait Appendable {
}
library
public class StringBuilder() : Appendable {
public class StringBuilder(capacity: Int? = null) : Appendable {
override fun append(c: Char): StringBuilder = noImpl
override fun append(csq: CharSequence?): StringBuilder = noImpl
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder = noImpl
+2 -1
View File
@@ -31,7 +31,8 @@ native public fun String.concat(str : String) : String = noImpl
native public fun String.match(regex : String) : Array<String> = noImpl
native public fun String.trim() : String = noImpl
//native public fun String.trim() : String = noImpl
//TODO: String.replace to implement effective trimLeading and trimTrailing
native("length")
public val CharSequence.size: Int get() = noImpl
+3 -3
View File
@@ -169,7 +169,7 @@ class StringTest {
assertEquals("a", "\na".trimLeading())
assertEquals("a=", "-=-=a=".trimLeading('-','='))
assertEquals("123a", "ab123a".trimLeading { !it.isDigit() })
assertEquals("123a", "ab123a".trimLeading { it < '0' || it > '9' }) // TODO: Use !it.isDigit when available in JS
}
test fun trimTrailing() {
@@ -188,7 +188,7 @@ class StringTest {
assertEquals("a", "a\n".trimTrailing())
assertEquals("=a", "=a=-=-".trimTrailing('-','='))
assertEquals("ab123", "ab123a".trimTrailing { !it.isDigit() })
assertEquals("ab123", "ab123a".trimTrailing { it < '0' || it > '9' }) // TODO: Use !it.isDigit when available in JS
}
test fun trimTrailingAndLeading() {
@@ -215,7 +215,7 @@ class StringTest {
)
val trimChars = charArray('-','=')
val trimPredicate = { (it: Char) -> !it.isDigit() }
val trimPredicate = { (it: Char) -> it < '0' || it > '9' } // TODO: Use !it.isDigit when available in JS
for (example in examplesForPredicate) {
assertEquals(example.trimLeading(*trimChars).trimTrailing(*trimChars), example.trim(*trimChars))
assertEquals(example.trimLeading(trimPredicate).trimTrailing(trimPredicate), example.trim(trimPredicate))