JS: arrayToString should use toString() instead of direct join to handle nulls properly

#KT-8663 Fixed
This commit is contained in:
Sergey Mashkov
2015-07-30 15:58:07 +03:00
parent 2826f193dd
commit 0e25a5ea82
4 changed files with 14 additions and 2 deletions
+2 -2
View File
@@ -96,7 +96,7 @@
}; };
Kotlin.arrayToString = function (a) { Kotlin.arrayToString = function (a) {
return "[" + a.join(", ") + "]"; return "[" + a.map(Kotlin.toString).join(", ") + "]";
}; };
Kotlin.compareTo = function (a, b) { Kotlin.compareTo = function (a, b) {
@@ -618,7 +618,7 @@
return this.array.slice(0); return this.array.slice(0);
}, },
toString: function () { toString: function () {
return "[" + this.array.join(", ") + "]"; return Kotlin.arrayToString(this.array);
}, },
toJSON: function () { toJSON: function () {
return this.array; return this.array;
@@ -665,5 +665,9 @@ class CollectionTest {
compare(linkedMapOf(2 to 3), mapOf(2 to 3)) { mapBehavior() } compare(linkedMapOf(2 to 3), mapOf(2 to 3)) { mapBehavior() }
} }
test fun toStringTest() {
// we need toString() inside pattern because of KT-8666
assertEquals("[1, a, null, ${Long.MAX_VALUE.toString()}]", listOf(1, "a", null, Long.MAX_VALUE).toString())
}
} }
@@ -60,4 +60,8 @@ class ListSpecificTest {
assertEquals(3, list.size()) assertEquals(3, list.size())
assertEquals("beverage,location,name", list.join(",")) assertEquals("beverage,location,name", list.join(","))
} }
Test fun testNullToString() {
assertEquals("[null]", listOf<String?>(null).toString())
}
} }
@@ -26,6 +26,10 @@ import org.junit.Test as test
class ReversedViewsTest { class ReversedViewsTest {
test fun testNullToString() {
assertEquals("[null]", listOf<String?>(null).asReversed().toString())
}
test fun testBehavior() { test fun testBehavior() {
val original = listOf(2L, 3L, Long.MAX_VALUE) val original = listOf(2L, 3L, Long.MAX_VALUE)
val reversed = original.reverse() val reversed = original.reverse()