Fix js-stdlib compilation and tests.
This commit is contained in:
@@ -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]")
|
||||||
@@ -37,7 +37,7 @@ public trait Appendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
library
|
library
|
||||||
public class StringBuilder() : Appendable {
|
public class StringBuilder(capacity: Int? = null) : Appendable {
|
||||||
override fun append(c: Char): StringBuilder = noImpl
|
override fun append(c: Char): StringBuilder = noImpl
|
||||||
override fun append(csq: CharSequence?): StringBuilder = noImpl
|
override fun append(csq: CharSequence?): StringBuilder = noImpl
|
||||||
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder = noImpl
|
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder = noImpl
|
||||||
|
|||||||
@@ -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.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")
|
native("length")
|
||||||
public val CharSequence.size: Int get() = noImpl
|
public val CharSequence.size: Int get() = noImpl
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class StringTest {
|
|||||||
assertEquals("a", "\na".trimLeading())
|
assertEquals("a", "\na".trimLeading())
|
||||||
|
|
||||||
assertEquals("a=", "-=-=a=".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() {
|
test fun trimTrailing() {
|
||||||
@@ -188,7 +188,7 @@ class StringTest {
|
|||||||
assertEquals("a", "a\n".trimTrailing())
|
assertEquals("a", "a\n".trimTrailing())
|
||||||
|
|
||||||
assertEquals("=a", "=a=-=-".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() {
|
test fun trimTrailingAndLeading() {
|
||||||
@@ -215,7 +215,7 @@ class StringTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val trimChars = charArray('-','=')
|
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) {
|
for (example in examplesForPredicate) {
|
||||||
assertEquals(example.trimLeading(*trimChars).trimTrailing(*trimChars), example.trim(*trimChars))
|
assertEquals(example.trimLeading(*trimChars).trimTrailing(*trimChars), example.trim(*trimChars))
|
||||||
assertEquals(example.trimLeading(trimPredicate).trimTrailing(trimPredicate), example.trim(trimPredicate))
|
assertEquals(example.trimLeading(trimPredicate).trimTrailing(trimPredicate), example.trim(trimPredicate))
|
||||||
|
|||||||
Reference in New Issue
Block a user