Rearrange kotlin-stdlib-js library sources
Move kotlin.* api inside kotlin directory. Update copyright paths.
This commit is contained in:
committed by
Stanislav Erokhin
parent
57e47d1830
commit
00b23a0fe9
@@ -0,0 +1,14 @@
|
||||
package test.js
|
||||
|
||||
import kotlin.js.*
|
||||
import kotlin.test.*
|
||||
|
||||
class JsonTest {
|
||||
|
||||
@Test fun createJsonFromPairs() {
|
||||
var obj = json(Pair("firstName", "John"), Pair("lastName", "Doe"), Pair("age", 30))
|
||||
assertEquals("John", obj["firstName"], "firstName")
|
||||
assertEquals("Doe", obj["lastName"], "lastName")
|
||||
assertEquals(30, obj["age"], "age")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package test.js
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class NumbersJsTest {
|
||||
|
||||
@Test fun longMinMaxValues() {
|
||||
assertEquals(js("Kotlin.Long.MIN_VALUE"), Long.MIN_VALUE)
|
||||
assertEquals(js("Kotlin.Long.MAX_VALUE"), Long.MAX_VALUE)
|
||||
}
|
||||
|
||||
@Test fun doubleMinMaxValues() {
|
||||
assertEquals(js("Number.MIN_VALUE"), Double.MIN_VALUE)
|
||||
assertEquals(js("Number.MAX_VALUE"), Double.MAX_VALUE)
|
||||
assertEquals(js("Number.POSITIVE_INFINITY"), Double.POSITIVE_INFINITY)
|
||||
assertEquals(js("Number.NEGATIVE_INFINITY"), Double.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
@Test fun floatMinMaxValues() {
|
||||
assertEquals(js("Number.MIN_VALUE"), Float.MIN_VALUE)
|
||||
assertEquals(js("Number.MAX_VALUE"), Float.MAX_VALUE)
|
||||
assertEquals(js("Number.POSITIVE_INFINITY"), Float.POSITIVE_INFINITY)
|
||||
assertEquals(js("Number.NEGATIVE_INFINITY"), Float.NEGATIVE_INFINITY)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 core
|
||||
|
||||
import test.assertStaticAndRuntimeTypeIs
|
||||
import test.assertStaticTypeIs
|
||||
import kotlin.js.Promise
|
||||
import kotlin.test.*
|
||||
|
||||
class PromiseTest {
|
||||
|
||||
// To be sure that some base cases can be written in Kotlin
|
||||
fun smokeTest(p: Promise<Int>, ps: Promise<String>) {
|
||||
assertStaticTypeIs<Promise<Int>>(p.then { 1 })
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(p.then({ 1 }))
|
||||
|
||||
val f: (Int) -> Int = { 1 }
|
||||
val ft: (Throwable) -> Int = { 1 }
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(p.then(f, ft))
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(
|
||||
p.then({
|
||||
1
|
||||
} , {
|
||||
1
|
||||
})
|
||||
)
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(
|
||||
p.then({
|
||||
1
|
||||
}) {
|
||||
1
|
||||
}
|
||||
)
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(
|
||||
p.then(onFulfilled = {
|
||||
1
|
||||
})
|
||||
)
|
||||
|
||||
assertStaticTypeIs<Promise<Int>>(
|
||||
p.then(onFulfilled = {
|
||||
1
|
||||
}) {
|
||||
1
|
||||
}
|
||||
)
|
||||
|
||||
p.then {
|
||||
ps
|
||||
}.then {
|
||||
assertStaticAndRuntimeTypeIs<String>(it)
|
||||
ps
|
||||
}.then(
|
||||
{
|
||||
assertStaticAndRuntimeTypeIs<String>(it)
|
||||
},
|
||||
{
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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 test.js
|
||||
|
||||
import kotlin.js.*
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class RegExpTest {
|
||||
|
||||
@Test fun regExpToString() {
|
||||
val pattern = "q(\\d+)d"
|
||||
val re = RegExp(pattern, "i")
|
||||
assertEquals("/$pattern/i", re.toString())
|
||||
}
|
||||
|
||||
@Test fun regExpProperties() {
|
||||
val re1 = RegExp("[a-z]", "img")
|
||||
assertTrue(re1.global)
|
||||
assertTrue(re1.ignoreCase)
|
||||
assertTrue(re1.multiline)
|
||||
val re2 = RegExp("\\d")
|
||||
assertFalse(re2.global)
|
||||
assertFalse(re2.ignoreCase)
|
||||
assertFalse(re2.multiline)
|
||||
}
|
||||
|
||||
@Test fun regExpTest() {
|
||||
val pattern = "q(\\d+)d"
|
||||
val re = RegExp(pattern, "i")
|
||||
|
||||
assertTrue(re.test("test q12D string"))
|
||||
assertFalse(re.test("sample"))
|
||||
|
||||
assertFalse(RegExp("\\w").test("?"))
|
||||
}
|
||||
|
||||
|
||||
@Test fun regExpExec() {
|
||||
val string = "R2D2 beats A5D5 "
|
||||
var re = RegExp("""(\w\d)(\w\d)""", "g")
|
||||
val m1 = re.exec(string)!!
|
||||
assertEquals(listOf("R2D2", "R2", "D2"), m1.asArray().asList())
|
||||
assertEquals(0, m1.index)
|
||||
assertEquals(4, re.lastIndex)
|
||||
|
||||
val m2 = re.exec(string)!!
|
||||
assertEquals(listOf("A5D5", "A5", "D5"), m2.asArray().asList())
|
||||
assertEquals(string.indexOf(m2[0]!!), m2.index)
|
||||
|
||||
val noMatch = re.exec(string)
|
||||
assertEquals(null, noMatch)
|
||||
assertEquals(0, re.lastIndex)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 test
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
public fun assertTypeEquals(expected: Any?, actual: Any?) {
|
||||
assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js })
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
internal inline fun String.removeLeadingPlusOnJava6(): String = this
|
||||
internal fun doubleTotalOrderEquals(a: Double?, b: Double?) = a == b || (a != a && b != b)
|
||||
Reference in New Issue
Block a user