StdLib deprecations cleanup: *array -> *arrayOf, copyToArray -> toTypedArray.
This commit is contained in:
@@ -732,7 +732,7 @@ public fun String.lastIndexOfAny(strings: Collection<String>, startIndex: Int =
|
||||
*/
|
||||
public fun String.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
indexOfAny(charArray(char), startIndex, ignoreCase)
|
||||
indexOfAny(charArrayOf(char), startIndex, ignoreCase)
|
||||
else
|
||||
nativeIndexOf(char, startIndex)
|
||||
}
|
||||
@@ -760,7 +760,7 @@ public fun String.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boole
|
||||
*/
|
||||
public fun String.lastIndexOf(char: Char, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
lastIndexOfAny(charArray(char), startIndex, ignoreCase)
|
||||
lastIndexOfAny(charArrayOf(char), startIndex, ignoreCase)
|
||||
else
|
||||
nativeLastIndexOf(char, startIndex)
|
||||
}
|
||||
|
||||
@@ -161,11 +161,11 @@ class ArraysTest {
|
||||
}
|
||||
|
||||
test fun average() {
|
||||
expect(0.0) { array<Int>().average() }
|
||||
expect(3.8) { array(1, 2, 5, 8, 3).average() }
|
||||
expect(2.1) { array(1.6, 2.6, 3.6, 0.6).average() }
|
||||
expect(100.0) { array<Byte>(100, 100, 100, 100, 100, 100).average() }
|
||||
expect(0) { array<Short>(1, -1, 2, -2, 3, -3).average().toShort() }
|
||||
expect(0.0) { arrayOf<Int>().average() }
|
||||
expect(3.8) { arrayOf(1, 2, 5, 8, 3).average() }
|
||||
expect(2.1) { arrayOf(1.6, 2.6, 3.6, 0.6).average() }
|
||||
expect(100.0) { arrayOf<Byte>(100, 100, 100, 100, 100, 100).average() }
|
||||
expect(0) { arrayOf<Short>(1, -1, 2, -2, 3, -3).average().toShort() }
|
||||
// TODO: Property based tests
|
||||
// for each arr with size 1 arr.average() == arr[0]
|
||||
// for each arr with size > 0 arr.average() = arr.sum().toDouble() / arr.size()
|
||||
@@ -296,7 +296,7 @@ class ArraysTest {
|
||||
}
|
||||
|
||||
test fun toPrimitiveArray() {
|
||||
val genericArray: Array<Int> = array(1, 2, 3)
|
||||
val genericArray: Array<Int> = arrayOf(1, 2, 3)
|
||||
val primitiveArray: IntArray = genericArray.toIntArray()
|
||||
expect(3) { primitiveArray.size() }
|
||||
assertEquals(genericArray.asList(), primitiveArray.asList())
|
||||
|
||||
@@ -348,10 +348,10 @@ class FilesTest {
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
|
||||
assert(stack.isEmpty())
|
||||
val sep = File.separator
|
||||
for (fileName in array("", "1", "1${sep}2", "1${sep}3", "6", "8")) {
|
||||
for (fileName in arrayOf("", "1", "1${sep}2", "1${sep}3", "6", "8")) {
|
||||
assert(dirs.contains(fileName), fileName)
|
||||
}
|
||||
for (fileName in array("1${sep}3${sep}4.txt", "1${sep}3${sep}4.txt", "7.txt", "8${sep}9.txt")) {
|
||||
for (fileName in arrayOf("1${sep}3${sep}4.txt", "1${sep}3${sep}4.txt", "7.txt", "8${sep}9.txt")) {
|
||||
assert(files.contains(fileName), fileName)
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ class FilesTest {
|
||||
forEach { it -> if (it != basedir) visitFile(it) }
|
||||
assert(stack.isEmpty())
|
||||
assert(dirs.size() == 1 && dirs.contains(""), dirs.size())
|
||||
for (file in array("1", "6", "7.txt", "8")) {
|
||||
for (file in arrayOf("1", "6", "7.txt", "8")) {
|
||||
assert(files.contains(file), file)
|
||||
}
|
||||
|
||||
@@ -376,11 +376,11 @@ class FilesTest {
|
||||
assert(stack.isEmpty())
|
||||
assert(failed.size() == 1 && failed.contains("1"), failed.size())
|
||||
assert(dirs.size() == 4, dirs.size())
|
||||
for (dir in array("", "1", "6", "8")) {
|
||||
for (dir in arrayOf("", "1", "6", "8")) {
|
||||
assert(dirs.contains(dir), dir)
|
||||
}
|
||||
assert(files.size() == 2, files.size())
|
||||
for (file in array("7.txt", "8${sep}9.txt")) {
|
||||
for (file in arrayOf("7.txt", "8${sep}9.txt")) {
|
||||
assert(files.contains(file), file)
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -73,9 +73,9 @@ class LinkedHashMapTest : MapJsTest() {
|
||||
|
||||
abstract class MapJsTest {
|
||||
val KEYS = listOf("zero", "one", "two", "three")
|
||||
val VALUES = array(0, 1, 2, 3).toList()
|
||||
val VALUES = arrayOf(0, 1, 2, 3).toList()
|
||||
|
||||
val SPECIAL_NAMES = array("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
|
||||
val SPECIAL_NAMES = arrayOf("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
|
||||
|
||||
test fun getOrElse() {
|
||||
val data = emptyMap()
|
||||
|
||||
@@ -16,7 +16,7 @@ class HtmlTemplateTest : TestCase() {
|
||||
|
||||
// TODO will use a tuple soon
|
||||
//val actual = StringTemplate(Tuple3<String,String,String>("<h1>", foo, "</h1> <p>hey ", bar, "</p>")).toHtml()
|
||||
val actual = StringTemplate(array("<h1>", foo, "</h1> <p>hey ", bar, "</p>")).toHtml()
|
||||
val actual = StringTemplate(arrayOf("<h1>", foo, "</h1> <p>hey ", bar, "</p>")).toHtml()
|
||||
|
||||
assertEquals("<h1>James</h1> <p>hey x > 1</p>", actual)
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ class LocaleTemplateTest : TestCase() {
|
||||
|
||||
// TODO will use a tuple soon
|
||||
//val actual = formatter.format(StringTemplate(Tuple2<String,String>("hello ", name))
|
||||
val actual = StringTemplate(array("hello ", name,
|
||||
" price ", price,
|
||||
" data ", now)).toString(formatter)
|
||||
val actual = StringTemplate(arrayOf("hello ", name,
|
||||
" price ", price,
|
||||
" data ", now)).toString(formatter)
|
||||
|
||||
println("Got text: $actual")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class StringTemplateTest : TestCase() {
|
||||
|
||||
// TODO will use a tuple soon
|
||||
//val actual = StringTemplate(Tuple3<String,String,String>("hello ", name, "!"))).toString()
|
||||
val actual = StringTemplate(array("hello ", name, "!")).toString()
|
||||
val actual = StringTemplate(arrayOf("hello ", name, "!")).toString()
|
||||
|
||||
assertEquals("hello James!", actual)
|
||||
}
|
||||
|
||||
@@ -262,8 +262,7 @@ class StringTest {
|
||||
}
|
||||
|
||||
test fun trimStartAndEnd() {
|
||||
val examples = array(
|
||||
"a",
|
||||
val examples = arrayOf("a",
|
||||
" a ",
|
||||
" a ",
|
||||
" a b ",
|
||||
@@ -279,12 +278,11 @@ class StringTest {
|
||||
assertEquals(example.trim(), example.trimStart().trimEnd())
|
||||
}
|
||||
|
||||
val examplesForPredicate = array(
|
||||
"123",
|
||||
val examplesForPredicate = arrayOf("123",
|
||||
"-=123=-"
|
||||
)
|
||||
|
||||
val trimChars = charArray('-','=')
|
||||
val trimChars = charArrayOf('-', '=')
|
||||
val trimPredicate = { it: Char -> it < '0' || it > '9' } // TODO: Use !it.isDigit when available in JS
|
||||
for (example in examplesForPredicate) {
|
||||
assertEquals(example.trimStart(*trimChars).trimEnd(*trimChars), example.trim(*trimChars))
|
||||
@@ -354,8 +352,8 @@ class StringTest {
|
||||
|
||||
test fun split() {
|
||||
assertEquals(listOf(""), "".split(";"))
|
||||
assertEquals(listOf("test"), "test".split(*charArray()), "empty list of delimiters, none matched -> entire string returned")
|
||||
assertEquals(listOf("test"), "test".split(*array<String>()), "empty list of delimiters, none matched -> entire string returned")
|
||||
assertEquals(listOf("test"), "test".split(*charArrayOf()), "empty list of delimiters, none matched -> entire string returned")
|
||||
assertEquals(listOf("test"), "test".split(*arrayOf<String>()), "empty list of delimiters, none matched -> entire string returned")
|
||||
|
||||
assertEquals(listOf("abc", "def", "123;456"), "abc;def,123;456".split(';', ',', limit = 3))
|
||||
assertEquals(listOf("abc", "def", "123", "456"), "abc<BR>def<br>123<bR>456".split("<BR>", ignoreCase = true))
|
||||
@@ -379,7 +377,7 @@ class StringTest {
|
||||
|
||||
test fun indexOfAnyChar() {
|
||||
val string = "abracadabra"
|
||||
val chars = charArray('d','b')
|
||||
val chars = charArrayOf('d', 'b')
|
||||
assertEquals(1, string.indexOfAny(chars))
|
||||
assertEquals(6, string.indexOfAny(chars, startIndex = 2))
|
||||
assertEquals(-1, string.indexOfAny(chars, startIndex = 9))
|
||||
@@ -388,12 +386,12 @@ class StringTest {
|
||||
assertEquals(6, string.lastIndexOfAny(chars, startIndex = 7))
|
||||
assertEquals(-1, string.lastIndexOfAny(chars, startIndex = 0))
|
||||
|
||||
assertEquals(-1, string.indexOfAny(charArray()))
|
||||
assertEquals(-1, string.indexOfAny(charArrayOf()))
|
||||
}
|
||||
|
||||
test fun indexOfAnyCharIgnoreCase() {
|
||||
val string = "abraCadabra"
|
||||
val chars = charArray('B','c')
|
||||
val chars = charArrayOf('B', 'c')
|
||||
assertEquals(1, string.indexOfAny(chars, ignoreCase = true))
|
||||
assertEquals(4, string.indexOfAny(chars, startIndex = 2, ignoreCase = true))
|
||||
assertEquals(-1, string.indexOfAny(chars, startIndex = 9, ignoreCase = true))
|
||||
@@ -473,8 +471,8 @@ class StringTest {
|
||||
assertEquals(2, string.lastIndexOf('e', 3))
|
||||
|
||||
for (startIndex in -1..string.length()+1) {
|
||||
assertEquals(string.indexOfAny(charArray('e'), startIndex), string.indexOf('e', startIndex))
|
||||
assertEquals(string.lastIndexOfAny(charArray('e'), startIndex), string.lastIndexOf('e', startIndex))
|
||||
assertEquals(string.indexOfAny(charArrayOf('e'), startIndex), string.indexOf('e', startIndex))
|
||||
assertEquals(string.lastIndexOfAny(charArrayOf('e'), startIndex), string.lastIndexOf('e', startIndex))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -490,8 +488,8 @@ class StringTest {
|
||||
|
||||
|
||||
for (startIndex in -1..string.length()+1){
|
||||
assertEquals(string.indexOfAny(charArray('e'), startIndex, ignoreCase = true), string.indexOf('E', startIndex, ignoreCase = true))
|
||||
assertEquals(string.lastIndexOfAny(charArray('E'), startIndex, ignoreCase = true), string.lastIndexOf('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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user