Migrate kotlin sources, maven projects and stdlib to new lambda syntax

This commit is contained in:
Stanislav Erokhin
2015-04-01 16:36:44 +03:00
parent e0988de707
commit b703f59e04
74 changed files with 136 additions and 140 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ class OrderingTest {
}
Test fun sortComparatorThenComparator() {
val comparator = comparator<Item> {(a, b) -> a.name.compareTo(b.name) } thenComparator {(a, b) -> a.rating.compareTo(b.rating) }
val comparator = comparator<Item> { a, b -> a.name.compareTo(b.name) } thenComparator { a, b -> a.rating.compareTo(b.rating) }
val diff = comparator.compare(v1, v2)
assertTrue(diff > 0)
@@ -200,7 +200,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
Test
fun mapIndexed() {
val shortened = data.mapIndexed {(index, value) -> value.substring(0..index) }
val shortened = data.mapIndexed { index, value -> value.substring(0..index) }
assertEquals(2, shortened.size())
assertEquals(listOf("f", "ba"), shortened)
}
@@ -84,7 +84,7 @@ public class SequenceTest {
}
test fun foldReducesTheFirstNElements() {
val sum = {(a: Int, b: Int) -> a + b }
val sum = { a: Int, b: Int -> a + b }
assertEquals(listOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
@@ -93,7 +93,7 @@ public class SequenceTest {
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile {(i: Int) -> i < 20 }.toList())
assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@@ -36,7 +36,7 @@ class SerializableTest() : TestCase() {
fun testComplexClosure() {
val y = 12
val fn1 = {(x: Int) -> (x + y).toString() }
val fn1 = { x: Int -> (x + y).toString() }
val fn2: Int.(Int) -> String = { fn1(this + it) }
val byteOutputStream = ByteArrayOutputStream()
@@ -8,7 +8,7 @@ class IteratorsJVMTest {
test fun flatMapAndTakeExtractTheTransformedElements() {
fun intToBinaryDigits() = { (i: Int) ->
fun intToBinaryDigits() = { i: Int ->
val binary = Integer.toBinaryString(i)!!
var index = 0
sequence<Char> { if (index < binary.length()) binary.get(index++) else null }
@@ -18,7 +18,7 @@ class IteratorsTest {
}
test fun foldReducesTheFirstNElements() {
val sum = { (a: Int, b: Int) -> a + b }
val sum = { a: Int, b: Int -> a + b }
assertEquals(arrayListOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
@@ -27,11 +27,11 @@ class IteratorsTest {
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(arrayListOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { (i: Int) -> i < 20 }.toList())
assertEquals(arrayListOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun mapIndexed() {
assertEquals(arrayListOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile {(i: Int) -> i < 20 }.toList())
assertEquals(arrayListOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@@ -12,7 +12,7 @@ class JavautilCollectionsTest {
val TEST_LIST = array(2, 0, 9, 7, 1).toList()
val SORTED_TEST_LIST = array(0, 1, 2, 7, 9).toList()
val MAX_ELEMENT = 9
val COMPARATOR = comparator { (x: Int, y: Int) -> if (x > y) 1 else if (x < y) -1 else 0 }
val COMPARATOR = comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }
test fun maxWithComparator() {
assertEquals(MAX_ELEMENT, Collections.max(TEST_LIST, COMPARATOR))
@@ -72,7 +72,7 @@ class TestObservablePropertyInChangeSupport: WithBox, ChangeSupport() {
class TestObservableProperty: WithBox {
var result = false
var b by Delegates.observable(1, {(pd, o, n) -> result = true})
var b by Delegates.observable(1, { pd, o, n -> result = true})
override fun box(): String {
b = 4
@@ -86,7 +86,7 @@ class A(val p: Boolean)
class TestVetoableProperty: WithBox {
var result = false
var b by Delegates.vetoable(A(true), {(pd, o, n) -> result = n.p == true; result})
var b by Delegates.vetoable(A(true), { pd, o, n -> result = n.p == true; result})
override fun box(): String {
val firstValue = A(true)
@@ -115,8 +115,8 @@ class TestMapPropertyString(): WithBox {
class TestMapValWithDefault(): WithBox {
val map = hashMapOf<String, String>()
val a: String by Delegates.mapVal(map, default = { ref, desc -> "aDefault" })
val b: String by FixedMapVal(map, default = { (ref: TestMapValWithDefault, desc: String) -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { (ref: TestMapValWithDefault, desc: String) -> "cDefault" }, key = { desc -> desc.name })
val b: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String {
if (a != "aDefault") return "fail at 'a'"
@@ -129,8 +129,8 @@ class TestMapValWithDefault(): WithBox {
class TestMapVarWithDefault(): WithBox {
val map = hashMapOf<String, Any?>()
var a: String by Delegates.mapVar(map, default = {ref, desc -> "aDefault" })
var b: String by FixedMapVar(map, default = {(ref: Any?, desc: String) -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {(ref: Any?, desc: String) -> "cDefault" }, key = { desc -> desc.name })
var b: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String {
if (a != "aDefault") return "fail at 'a'"
+4 -4
View File
@@ -290,7 +290,7 @@ class StringJVMTest {
test fun testReplaceAllClosure() {
val s = "test123zzz"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("test[123]zzz", result)
@@ -298,7 +298,7 @@ class StringJVMTest {
test fun testReplaceAllClosureAtStart() {
val s = "123zzz"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("[123]zzz", result)
@@ -306,7 +306,7 @@ class StringJVMTest {
test fun testReplaceAllClosureAtEnd() {
val s = "test123"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("test[123]", result)
@@ -314,7 +314,7 @@ class StringJVMTest {
test fun testReplaceAllClosureEmpty() {
val s = ""
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"x"
}
assertEquals("", result)
+1 -1
View File
@@ -285,7 +285,7 @@ class StringTest {
)
val trimChars = charArray('-','=')
val trimPredicate = { (it: Char) -> it < '0' || it > '9' } // TODO: Use !it.isDigit when available in JS
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))
assertEquals(example.trimStart(trimPredicate).trimEnd(trimPredicate), example.trim(trimPredicate))