From f2b9b370e140a61f0755c22c9a3dbd2c6f98833b Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 12 Sep 2014 14:33:23 +0400 Subject: [PATCH] Clean Dom and Dom tests. --- libraries/stdlib/src/kotlin/dom/Dom.kt | 8 +------ libraries/stdlib/src/kotlin/dom/DomEvents.kt | 22 ++++++-------------- libraries/stdlib/src/kotlin/dom/DomJVM.kt | 6 +++--- libraries/stdlib/test/dom/DomBuilderTest.kt | 5 ----- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/libraries/stdlib/src/kotlin/dom/Dom.kt b/libraries/stdlib/src/kotlin/dom/Dom.kt index 7268068150a..5e4cc83e3c7 100644 --- a/libraries/stdlib/src/kotlin/dom/Dom.kt +++ b/libraries/stdlib/src/kotlin/dom/Dom.kt @@ -333,13 +333,7 @@ public fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String { /** Converts the collection of nodes to an XML String */ public fun nodesToXmlString(nodes: Iterable, xmlDeclaration: Boolean = false): String { - // TODO this should work... - // return this.map{it.toXmlString()}.join("") - val builder = StringBuilder() - for (n in nodes) { - builder.append(n.toXmlString(xmlDeclaration)) - } - return builder.toString() + return nodes.map { it.toXmlString(xmlDeclaration) }.join() } // Syntax sugar diff --git a/libraries/stdlib/src/kotlin/dom/DomEvents.kt b/libraries/stdlib/src/kotlin/dom/DomEvents.kt index 9a16c460ceb..758a2337af8 100644 --- a/libraries/stdlib/src/kotlin/dom/DomEvents.kt +++ b/libraries/stdlib/src/kotlin/dom/DomEvents.kt @@ -5,23 +5,17 @@ import org.w3c.dom.Node import org.w3c.dom.events.* /** -* Turns an event handler function into an [EventListener] -*/ + * Turns an event handler function into an [EventListener] + */ public fun eventHandler(handler: (Event) -> Unit): EventListener { return EventListenerHandler(handler) } private class EventListenerHandler(private val handler: (Event) -> Unit) : EventListener { public override fun handleEvent(e: Event) { - if (e != null) { - handler(e) - } + handler(e) } -/* - TODO: needs KT-2507 fixed - - public override fun toString(): String? = "EventListenerHandler($handler)" -*/ + public override fun toString(): String = "EventListenerHandler($handler)" } public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener { @@ -56,16 +50,12 @@ private class CloseableEventListener( private val listener: EventListener, private val name: String, private val capture: Boolean -) : Closeable { + ) : Closeable { public override fun close() { target.removeEventListener(name, listener, capture) } -/* - TODO: needs KT-2507 fixed - - public override fun toString(): String? = "CloseableEventListener($target, $name)" -*/ + public override fun toString(): String = "CloseableEventListener($target, $name)" } public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? { diff --git a/libraries/stdlib/src/kotlin/dom/DomJVM.kt b/libraries/stdlib/src/kotlin/dom/DomJVM.kt index d826b56b709..dd8b752a310 100644 --- a/libraries/stdlib/src/kotlin/dom/DomJVM.kt +++ b/libraries/stdlib/src/kotlin/dom/DomJVM.kt @@ -156,12 +156,12 @@ public fun Element.removeClass(cssClass: String): Boolean { /** Creates a new document with the given document builder*/ public fun createDocument(builder: DocumentBuilder): Document { - return builder.newDocument()!! + return builder.newDocument() } /** Creates a new document with an optional DocumentBuilderFactory */ public fun createDocument(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): Document { - return createDocument(builderFactory.newDocumentBuilder()!!) + return createDocument(builderFactory.newDocumentBuilder()) } /** @@ -175,7 +175,7 @@ public fun defaultDocumentBuilderFactory(): DocumentBuilderFactory { * Returns the default [[DocumentBuilder]] */ public fun defaultDocumentBuilder(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): DocumentBuilder { - return builderFactory.newDocumentBuilder()!! + return builderFactory.newDocumentBuilder() } /** diff --git a/libraries/stdlib/test/dom/DomBuilderTest.kt b/libraries/stdlib/test/dom/DomBuilderTest.kt index b8d73209f0b..d41659a9ec4 100644 --- a/libraries/stdlib/test/dom/DomBuilderTest.kt +++ b/libraries/stdlib/test/dom/DomBuilderTest.kt @@ -37,8 +37,6 @@ class DomBuilderTest() { } } } - println("builder document: ${doc.toXmlString()}") - // test css selections on document assertEquals(0, doc[".doesNotExist"].size()) @@ -90,7 +88,6 @@ class DomBuilderTest() { } val grandChild = doc["grandChild"].first if (grandChild != null) { - println("got element ${grandChild.toXmlString()} with text '${grandChild.text}`") assertEquals("Hello World!", grandChild.text) assertEquals(" bar tiny", grandChild.attribute("class")) @@ -127,8 +124,6 @@ class DomBuilderTest() { fail("No child found!") } val children = doc.documentElement.children() - val xml = nodesToXmlString(children) - println("root element has children: ${xml}") assertEquals(1, children.size()) }