compile the assertions and a test case to QUnit on JS and got a working example to run the unit test case - yay!

This commit is contained in:
James Strachan
2012-06-13 16:14:13 +01:00
parent 9394e21208
commit 3765e85ca8
12 changed files with 170 additions and 76 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
package java.lang
import java.util.Iterator;
import java.util.Iterator
import js.library
library
+1
View File
@@ -2,3 +2,4 @@ package org.junit;
native
annotation class Test(name : String = "") {}
+11
View File
@@ -0,0 +1,11 @@
package QUnit
import js.native
/**
* The [QUnit](http://qunitjs.com/) API
*/
native
fun ok(actual: Boolean, message: String): Unit = js.noImpl;
+39
View File
@@ -0,0 +1,39 @@
package kotlin.test
/**
* Comments out a block of test code until it is implemented while keeping a link to the code
* to implement in your unit test output
*/
public inline fun todo(block: ()-> Any) {
// println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
println("TODO at " + block)
}
/**
* Provides the JS implementation of asserter using [QUnit](http://QUnitjs.com/)
*/
public var asserter: Asserter = QUnitAsserter()
public class QUnitAsserter(): Asserter {
public override fun assertTrue(message: String, actual: Boolean) {
QUnit.ok(actual, message)
}
public override fun assertEquals(message: String, expected: Any?, actual: Any?) {
QUnit.ok(expected == actual, "$message. Expected <$expected> actual <$actual>")
}
public override fun assertNotNull(message: String, actual: Any?) {
QUnit.ok(actual != null, message)
}
public override fun assertNull(message: String, actual: Any?) {
QUnit.ok(actual == null, message)
}
public override fun fail(message: String) {
QUnit.ok(false, message)
}
}