Clean Dom and Dom tests.

This commit is contained in:
Ilya Ryzhenkov
2014-09-12 14:33:23 +04:00
committed by Andrey Breslav
parent cde74504d4
commit f2b9b370e1
4 changed files with 10 additions and 31 deletions
+1 -7
View File
@@ -333,13 +333,7 @@ public fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
/** Converts the collection of nodes to an XML String */ /** Converts the collection of nodes to an XML String */
public fun nodesToXmlString(nodes: Iterable<Node>, xmlDeclaration: Boolean = false): String { public fun nodesToXmlString(nodes: Iterable<Node>, xmlDeclaration: Boolean = false): String {
// TODO this should work... return nodes.map { it.toXmlString(xmlDeclaration) }.join()
// return this.map{it.toXmlString()}.join("")
val builder = StringBuilder()
for (n in nodes) {
builder.append(n.toXmlString(xmlDeclaration))
}
return builder.toString()
} }
// Syntax sugar // Syntax sugar
+6 -16
View File
@@ -5,23 +5,17 @@ import org.w3c.dom.Node
import org.w3c.dom.events.* 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 { public fun eventHandler(handler: (Event) -> Unit): EventListener {
return EventListenerHandler(handler) return EventListenerHandler(handler)
} }
private class EventListenerHandler(private val handler: (Event) -> Unit) : EventListener { private class EventListenerHandler(private val handler: (Event) -> Unit) : EventListener {
public override fun handleEvent(e: Event) { public override fun handleEvent(e: Event) {
if (e != null) { handler(e)
handler(e)
}
} }
/* public override fun toString(): String = "EventListenerHandler($handler)"
TODO: needs KT-2507 fixed
public override fun toString(): String? = "EventListenerHandler($handler)"
*/
} }
public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener { public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener {
@@ -56,16 +50,12 @@ private class CloseableEventListener(
private val listener: EventListener, private val listener: EventListener,
private val name: String, private val name: String,
private val capture: Boolean private val capture: Boolean
) : Closeable { ) : Closeable {
public override fun close() { public override fun close() {
target.removeEventListener(name, listener, capture) target.removeEventListener(name, listener, capture)
} }
/* public override fun toString(): String = "CloseableEventListener($target, $name)"
TODO: needs KT-2507 fixed
public override fun toString(): String? = "CloseableEventListener($target, $name)"
*/
} }
public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? { public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? {
+3 -3
View File
@@ -156,12 +156,12 @@ public fun Element.removeClass(cssClass: String): Boolean {
/** Creates a new document with the given document builder*/ /** Creates a new document with the given document builder*/
public fun createDocument(builder: DocumentBuilder): Document { public fun createDocument(builder: DocumentBuilder): Document {
return builder.newDocument()!! return builder.newDocument()
} }
/** Creates a new document with an optional DocumentBuilderFactory */ /** Creates a new document with an optional DocumentBuilderFactory */
public fun createDocument(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): Document { 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]] * Returns the default [[DocumentBuilder]]
*/ */
public fun defaultDocumentBuilder(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): DocumentBuilder { public fun defaultDocumentBuilder(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): DocumentBuilder {
return builderFactory.newDocumentBuilder()!! return builderFactory.newDocumentBuilder()
} }
/** /**
@@ -37,8 +37,6 @@ class DomBuilderTest() {
} }
} }
} }
println("builder document: ${doc.toXmlString()}")
// test css selections on document // test css selections on document
assertEquals(0, doc[".doesNotExist"].size()) assertEquals(0, doc[".doesNotExist"].size())
@@ -90,7 +88,6 @@ class DomBuilderTest() {
} }
val grandChild = doc["grandChild"].first val grandChild = doc["grandChild"].first
if (grandChild != null) { if (grandChild != null) {
println("got element ${grandChild.toXmlString()} with text '${grandChild.text}`")
assertEquals("Hello World!", grandChild.text) assertEquals("Hello World!", grandChild.text)
assertEquals(" bar tiny", grandChild.attribute("class")) assertEquals(" bar tiny", grandChild.attribute("class"))
@@ -127,8 +124,6 @@ class DomBuilderTest() {
fail("No child found!") fail("No child found!")
} }
val children = doc.documentElement.children() val children = doc.documentElement.children()
val xml = nodesToXmlString(children)
println("root element has children: ${xml}")
assertEquals(1, children.size()) assertEquals(1, children.size())
} }