From 949b2ce070daa4a2bcf7e40a0e3e9e70dc5d6223 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 28 Feb 2012 11:56:49 +0000 Subject: [PATCH] moved the common test helper methods into the kool.test package as a reusable library --- build.xml | 3 +- kunit/src/main/kotlin/Test.kt | 42 +- testlib/module.kt | 3 +- testlib/test/CollectionTest.kt | 457 +++++++++--------- testlib/test/EnymerationIteratorTest.kt | 2 +- testlib/test/GetOrElseTest.kt | 2 +- testlib/test/IoTest.kt | 2 +- testlib/test/JavaClassTest.kt | 2 +- testlib/test/ListTest.kt | 2 +- testlib/test/MapTest.kt | 62 +-- testlib/test/MathTest.kt | 2 +- testlib/test/OldStdlibTest.kt | 4 +- testlib/test/SetTest.kt | 112 ++--- testlib/test/StandardCollectionTest.kt | 4 +- testlib/test/StdLibIssuesTest.kt | 2 +- testlib/test/StringTest.kt | 2 +- testlib/test/dom/DomBuilderTest.kt | 6 +- testlib/test/dom/DomTest.kt | 2 +- .../test/language/NullableCollectionsTest.kt | 2 +- testlib/test/properties/PropertiesTest.kt | 2 +- 20 files changed, 361 insertions(+), 354 deletions(-) diff --git a/build.xml b/build.xml index b5931e595ce..e6fb4a76a9c 100644 --- a/build.xml +++ b/build.xml @@ -133,7 +133,7 @@ - + @@ -157,6 +157,7 @@ + diff --git a/kunit/src/main/kotlin/Test.kt b/kunit/src/main/kotlin/Test.kt index 2ce0fb64375..30fbd211eca 100644 --- a/kunit/src/main/kotlin/Test.kt +++ b/kunit/src/main/kotlin/Test.kt @@ -4,66 +4,62 @@ package kool.test import org.junit.Assert +import junit.framework.TestCase /** Asserts that the given block returns true */ -fun assert(message: String, block: ()-> Boolean) { +inline fun assertTrue(message: String, block: ()-> Boolean) { val actual = block() Assert.assertTrue(message, actual) } /** Asserts that the given block returns true */ -fun assert(block: ()-> Boolean) = assert(block.toString(), block) +inline fun assertTrue(block: ()-> Boolean) = assertTrue(block.toString(), block) /** Asserts that the given block returns false */ -fun assertNot(message: String, block: ()-> Boolean) { - assert(message){ !block() } +inline fun assertNot(message: String, block: ()-> Boolean) { + assertTrue(message){ !block() } } /** Asserts that the given block returns true */ -fun assertNot(block: ()-> Boolean) = assertNot(block.toString(), block) +inline fun assertNot(block: ()-> Boolean) = assertNot(block.toString(), block) /** Asserts that the expression is true with an optional message */ -fun assert(actual: Boolean, message: String = "") { - assertTrue(actual, message) -} - -/** Asserts that the expression is true with an optional message */ -fun assertTrue(actual: Boolean, message: String = "") { +inline fun assertTrue(actual: Boolean, message: String = "") { return assertEquals(true, actual, message) } /** Asserts that the expression is false with an optional message */ -fun assertFalse(actual: Boolean, message: String = "") { +inline fun assertFalse(actual: Boolean, message: String = "") { return assertEquals(false, actual, message) } /** Asserts that the expected value is equal to the actual value, with an optional message */ -fun assertEquals(expected: Any?, actual: Any?, message: String = "") { +inline fun assertEquals(expected: Any?, actual: Any?, message: String = "") { Assert.assertEquals(message, expected, actual) } /** Asserts that the expression is not null, with an optional message */ -fun assertNotNull(actual: Any?, message: String = "") { +inline fun assertNotNull(actual: Any?, message: String = "") { Assert.assertNotNull(message, actual) } /** Asserts that the expression is null, with an optional message */ -fun assertNull(actual: Any?, message: String = "") { +inline fun assertNull(actual: Any?, message: String = "") { Assert.assertNull(message, actual) } /** Marks a test as having failed if this point in the execution path is reached, with an optional message */ -fun fail(message: String = "") { +inline fun fail(message: String = "") { Assert.fail(message) } /** Asserts that given function block returns the given expected value */ -fun expect(expected: T, block: ()-> T) { +inline fun expect(expected: T, block: ()-> T) { expect(expected, block.toString(), block) } /** Asserts that given function block returns the given expected value and use the given message if it fails */ -fun expect(expected: T, message: String, block: ()-> T) { +inline fun expect(expected: T, message: String, block: ()-> T) { val actual = block() assertEquals(expected, actual, message) } @@ -95,6 +91,14 @@ fun failsWith(block: ()-> Any) { * 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 */ -fun todo(block: ()-> Any) { +inline fun todo(block: ()-> Any) { println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block) } + + +/** + * Useful base class for test cases using the old JUnit 3 naming convention of functions + * starting with "test*" as being a test case + */ +abstract class TestSupport() : TestCase() { +} diff --git a/testlib/module.kt b/testlib/module.kt index a93cdb2cfd4..dd8310e6a17 100644 --- a/testlib/module.kt +++ b/testlib/module.kt @@ -3,7 +3,8 @@ import kotlin.modules.* fun project() { module("testlib") { // TODO how to refer to the dir of the module? - classpath += "testlib/lib/junit-4.9.jar" + classpath += "dist/kotlinc/lib/kotlin-test.jar" + classpath += "kunit/lib/junit-4.9.jar" addSourceFiles("test") } diff --git a/testlib/test/CollectionTest.kt b/testlib/test/CollectionTest.kt index 0d8749f662b..5db34d064b1 100644 --- a/testlib/test/CollectionTest.kt +++ b/testlib/test/CollectionTest.kt @@ -1,271 +1,272 @@ package test.collections +import kool.test.* + // TODO can we avoid importing all this stuff by default I wonder? // e.g. making println and the collection builder methods public by default? import std.* import std.io.* import std.util.* -import stdhack.test.* import java.util.* class CollectionTest() : TestSupport() { - class IterableWrapper(collection : java.lang.Iterable) : java.lang.Iterable { - private val collection = collection + class IterableWrapper(collection : java.lang.Iterable) : java.lang.Iterable { + private val collection = collection - override fun iterator(): java.util.Iterator { - return collection.iterator().sure() - } - } - - - val data = arrayList("foo", "bar") - - fun testAny() { - assert { - data.any{it.startsWith("f")} - } - assertNot { - data.any{it.startsWith("x")} - } - } - - fun testAll() { - assert { - data.all{it.length == 3} - } - assertNot { - data.all{s -> s.startsWith("b")} - } - } - - fun testCount() { - assertEquals(1, data.count{it.startsWith("b")}) - assertEquals(2, data.count{it.size == 3}) - } - - fun testFilter() { - val foo = data.filter{it.startsWith("f")} - - assert { - foo.all{it.startsWith("f")} - } - assertEquals(1, foo.size) - assertEquals(arrayList("foo"), foo) - } - - fun testFilterNot() { - val foo = data.filterNot{it.startsWith("b")} - - assert { - foo.all{it.startsWith("f")} - } - assertEquals(1, foo.size) - assertEquals(arrayList("foo"), foo) - } - - fun testFilterIntoLinkedList() { - // TODO would be nice to avoid the - val foo = data.filter(linkedList()){it.startsWith("f")} - - assert { - foo.all{it.startsWith("f")} - } - assertEquals(1, foo.size) - assertEquals(linkedList("foo"), foo) - - assert { - foo is LinkedList - } - } - - fun testFilterIntoSortedSet() { - // TODO would be nice to avoid the - val foo = data.filter(hashSet()){it.startsWith("f")} - - assert { - foo.all{it.startsWith("f")} - } - assertEquals(1, foo.size) - assertEquals(hashSet("foo"), foo) - - assert { - foo is HashSet - } - } - - fun testFind() { - val x = data.find{it.startsWith("x")} - assertNull(x) - fails { - x.sure() + override fun iterator(): java.util.Iterator { + return collection.iterator().sure() + } } - val f = data.find{it.startsWith("f")} - f.sure() - assertEquals("foo", f) - } - fun testFlatMap() { - val characters = arrayList('f', 'o', 'o', 'b', 'a', 'r') - // TODO figure out how to get a line like this to compile :) - /* - val characters = data.flatMap{ - it.toCharArray().toList() as Collection - } - */ - todo { - println("Got list of characters ${characters}") - val text = characters.join("") - assertEquals("foobar", text) - } - } + val data = arrayList("foo", "bar") - fun testForeach() { - var count = 0 - data.foreach{ count += it.length } - assertEquals(6, count) - } - - fun testFold() { - expect(10) { - val numbers = arrayList(1, 2, 3, 4) - - // TODO would be nice to be able to write this as this - //numbers.fold(0){it + it2} - numbers.fold(0){(it, it2) -> it + it2} + fun testAny() { + assertTrue { + data.any{it.startsWith("f")} + } + assertNot { + data.any{it.startsWith("x")} + } } - expect(0) { - val numbers = arrayList() - numbers.fold(0){(it, it2) -> it + it2} + fun testAll() { + assertTrue { + data.all{it.length == 3} + } + assertNot { + data.all{s -> s.startsWith("b")} + } } - expect("1234") { - val numbers = arrayList(1, 2, 3, 4) - - // TODO would be nice to be able to write this as this - // numbers.map{it.toString()}.fold(""){it + it2} - numbers.map{it.toString()}.fold(""){(it, it2) -> it + it2} + fun testCount() { + assertEquals(1, data.count{it.startsWith("b")}) + assertEquals(2, data.count{it.size == 3}) } - } - fun testFoldRight() { - expect("4321") { - val numbers = arrayList(1, 2, 3, 4) + fun testFilter() { + val foo = data.filter{it.startsWith("f")} - // TODO would be nice to be able to write this as this - // numbers.map{it.toString()}.foldRight(""){it + it2} - numbers.map{it.toString()}.foldRight(""){(it, it2) -> it + it2} + assertTrue { + foo.all{it.startsWith("f")} + } + assertEquals(1, foo.size) + assertEquals(arrayList("foo"), foo) } - } + fun testFilterNot() { + val foo = data.filterNot{it.startsWith("b")} - fun testGroupBy() { - val words = arrayList("a", "ab", "abc", "def", "abcd") - /* - TODO inference engine should not need this type info? - */ - val byLength = words.groupBy{it.length} - assertEquals(4, byLength.size()) - - println("Grouped by length is: $byLength") - /* - TODO compiler bug... - - val l3 = byLength.getOrElse(3, {ArrayList()}) - assertEquals(2, l3.size) - */ - - } - - fun testJoin() { - val text = data.join("-", "<", ">") - assertEquals("", text) - } - - fun testMap() { - /** - TODO compiler bug - we should be able to remove the explicit type on the function - http://youtrack.jetbrains.net/issue/KT-1145 - */ - val lengths = data.map{s -> s.length} - assert { - lengths.all{it == 3} + assertTrue { + foo.all{it.startsWith("f")} + } + assertEquals(1, foo.size) + assertEquals(arrayList("foo"), foo) } - assertEquals(2, lengths.size) - assertEquals(arrayList(3, 3), lengths) - } - fun testReverse() { - val rev = data.reverse() - assertEquals(arrayList("bar", "foo"), rev) - } + fun testFilterIntoLinkedList() { + // TODO would be nice to avoid the + val foo = data.filter(linkedList()){it.startsWith("f")} - fun testSort() { - val coll: List = arrayList("foo", "bar", "abc") + assertTrue { + foo.all{it.startsWith("f")} + } + assertEquals(1, foo.size) + assertEquals(linkedList("foo"), foo) - // TODO fixme - // Some sort of in/out variance thing - or an issue with Java interop? - //coll.sort() - todo { - assertEquals(3, coll.size) - assertEquals(arrayList("abc", "bar", "foo"), coll) + assertTrue { + foo is LinkedList + } + } + + fun testFilterIntoSortedSet() { + // TODO would be nice to avoid the + val foo = data.filter(hashSet()){it.startsWith("f")} + + assertTrue { + foo.all{it.startsWith("f")} + } + assertEquals(1, foo.size) + assertEquals(hashSet("foo"), foo) + + assertTrue { + foo is HashSet + } + } + + fun testFind() { + val x = data.find{it.startsWith("x")} + assertNull(x) + fails { + x.sure() + } + + val f = data.find{it.startsWith("f")} + f.sure() + assertEquals("foo", f) + } + + fun testFlatMap() { + val characters = arrayList('f', 'o', 'o', 'b', 'a', 'r') + // TODO figure out how to get a line like this to compile :) + /* + val characters = data.flatMap{ + it.toCharArray().toList() as Collection + } + */ + todo { + println("Got list of characters ${characters}") + val text = characters.join("") + assertEquals("foobar", text) + } + } + + fun testForeach() { + var count = 0 + data.foreach{ count += it.length } + assertEquals(6, count) + } + + fun testFold() { + expect(10) { + val numbers = arrayList(1, 2, 3, 4) + + // TODO would be nice to be able to write this as this + //numbers.fold(0){it + it2} + numbers.fold(0){(it, it2) -> it + it2} + } + + expect(0) { + val numbers = arrayList() + numbers.fold(0){(it, it2) -> it + it2} + } + + expect("1234") { + val numbers = arrayList(1, 2, 3, 4) + + // TODO would be nice to be able to write this as this + // numbers.map{it.toString()}.fold(""){it + it2} + numbers.map{it.toString()}.fold(""){(it, it2) -> it + it2} + } + } + + fun testFoldRight() { + expect("4321") { + val numbers = arrayList(1, 2, 3, 4) + + // TODO would be nice to be able to write this as this + // numbers.map{it.toString()}.foldRight(""){it + it2} + numbers.map{it.toString()}.foldRight(""){(it, it2) -> it + it2} + } + } + + + fun testGroupBy() { + val words = arrayList("a", "ab", "abc", "def", "abcd") + /* + TODO inference engine should not need this type info? + */ + val byLength = words.groupBy{it.length} + assertEquals(4, byLength.size()) + + println("Grouped by length is: $byLength") + /* + TODO compiler bug... + + val l3 = byLength.getOrElse(3, {ArrayList()}) + assertEquals(2, l3.size) + */ } - } - fun testToArray() { - val arr = data.toArray() - println("Got array ${arr}") - todo { - assert { - arr is Array - } + fun testJoin() { + val text = data.join("-", "<", ">") + assertEquals("", text) } - } - fun testSimpleCount() { - assertEquals(2, data.count()) - assertEquals(3, hashSet(12, 14, 15).count()) - assertEquals(0, ArrayList().count()) - } + fun testMap() { + /** + TODO compiler bug + we should be able to remove the explicit type on the function + http://youtrack.jetbrains.net/issue/KT-1145 + */ + val lengths = data.map{s -> s.length} + assertTrue { + lengths.all{it == 3} + } + assertEquals(2, lengths.size) + assertEquals(arrayList(3, 3), lengths) + } - fun testLast() { - assertEquals("bar", data.last()) - assertEquals(25, arrayList(15, 19, 20, 25).last()) - // assertEquals(19, TreeSet(arrayList(90, 47, 19)).first()) - assertEquals('a', linkedList('a').last()) - } + fun testReverse() { + val rev = data.reverse() + assertEquals(arrayList("bar", "foo"), rev) + } - fun testLastException() { - fails { arrayList().last() } - fails { linkedList().last() } - fails { hashSet().last() } - } + fun testSort() { + val coll: List = arrayList("foo", "bar", "abc") - fun testIndices() { - val indices = data.indices - assertEquals(0, indices.start) - assertEquals(1, indices.end) - assertEquals(2, indices.size) - assertFalse(indices.isReversed) - } + // TODO fixme + // Some sort of in/out variance thing - or an issue with Java interop? + //coll.sort() + todo { + assertEquals(3, coll.size) + assertEquals(arrayList("abc", "bar", "foo"), coll) - fun testContains() { - assertTrue(data.contains("foo")) - assertTrue(data.contains("bar")) - assertFalse(data.contains("some")) + } + } - // TODO: Problems with generation -// assertTrue(IterableWrapper(data).contains("bar")) -// assertFalse(IterableWrapper(data).contains("some")) + fun testToArray() { + val arr = data.toArray() + println("Got array ${arr}") + todo { + assertTrue { + arr is Array + } + } + } - assertFalse(hashSet().contains(12)) - assertTrue(linkedList(15, 19, 20).contains(15)) + fun testSimpleCount() { + assertEquals(2, data.count()) + assertEquals(3, hashSet(12, 14, 15).count()) + assertEquals(0, ArrayList().count()) + } -// assertTrue(IterableWrapper(hashSet(45, 14, 13)).contains(14)) -// assertFalse(IterableWrapper(linkedList()).contains(15)) - } + fun testLast() { + assertEquals("bar", data.last()) + assertEquals(25, arrayList(15, 19, 20, 25).last()) + // assertEquals(19, TreeSet(arrayList(90, 47, 19)).first()) + assertEquals('a', linkedList('a').last()) + } + + fun testLastException() { + fails { arrayList().last() } + fails { linkedList().last() } + fails { hashSet().last() } + } + + fun testIndices() { + val indices = data.indices + assertEquals(0, indices.start) + assertEquals(1, indices.end) + assertEquals(2, indices.size) + assertFalse(indices.isReversed) + } + + fun testContains() { + assertTrue(data.contains("foo")) + assertTrue(data.contains("bar")) + assertFalse(data.contains("some")) + + // TODO: Problems with generation + // assertTrue(IterableWrapper(data).contains("bar")) + // assertFalse(IterableWrapper(data).contains("some")) + + assertFalse(hashSet().contains(12)) + assertTrue(linkedList(15, 19, 20).contains(15)) + + // assertTrue(IterableWrapper(hashSet(45, 14, 13)).contains(14)) + // assertFalse(IterableWrapper(linkedList()).contains(15)) + } } diff --git a/testlib/test/EnymerationIteratorTest.kt b/testlib/test/EnymerationIteratorTest.kt index f50b9d5a961..45663d09cf6 100644 --- a/testlib/test/EnymerationIteratorTest.kt +++ b/testlib/test/EnymerationIteratorTest.kt @@ -1,7 +1,7 @@ import java.util.Vector import junit.framework.TestCase -import stdhack.test.assertEquals +import kool.test.assertEquals class EnumerationIteratorTest() : TestCase() { fun testIteration () { diff --git a/testlib/test/GetOrElseTest.kt b/testlib/test/GetOrElseTest.kt index 755c94ae98d..6223877fc63 100644 --- a/testlib/test/GetOrElseTest.kt +++ b/testlib/test/GetOrElseTest.kt @@ -1,7 +1,7 @@ package test.standard import std.* -import stdhack.test.* +import kool.test.* class GetOrElseTest() : TestSupport() { val v1: String? = "hello" diff --git a/testlib/test/IoTest.kt b/testlib/test/IoTest.kt index b910831195a..a2a9043cc4f 100644 --- a/testlib/test/IoTest.kt +++ b/testlib/test/IoTest.kt @@ -1,6 +1,6 @@ package test.collections -import stdhack.test.* +import kool.test.* import std.io.* import std.util.* diff --git a/testlib/test/JavaClassTest.kt b/testlib/test/JavaClassTest.kt index e436a701047..06e4eb0eb9b 100644 --- a/testlib/test/JavaClassTest.kt +++ b/testlib/test/JavaClassTest.kt @@ -1,6 +1,6 @@ package testjc -import stdhack.test.* +import kool.test.* class C() diff --git a/testlib/test/ListTest.kt b/testlib/test/ListTest.kt index 8fb628735db..531b5e97508 100644 --- a/testlib/test/ListTest.kt +++ b/testlib/test/ListTest.kt @@ -1,6 +1,6 @@ package test.collections -import stdhack.test.* +import kool.test.* // TODO can we avoid importing all this stuff by default I wonder? // e.g. making println and the collection builder methods public by default? diff --git a/testlib/test/MapTest.kt b/testlib/test/MapTest.kt index 8550e457c84..aa5894a8970 100644 --- a/testlib/test/MapTest.kt +++ b/testlib/test/MapTest.kt @@ -1,6 +1,6 @@ package test.collections -import stdhack.test.* +import kool.test.* // TODO can we avoid importing all this stuff by default I wonder? // e.g. making println and the collection builder methods public by default? @@ -10,43 +10,43 @@ import std.util.* import java.util.* class MapTest() : TestSupport() { - val data: java.util.Map = java.util.HashMap() + val data: java.util.Map = java.util.HashMap() - fun testGetOrElse() { - val a = data.getOrElse("foo"){2} - assertEquals(2, a) + fun testGetOrElse() { + val a = data.getOrElse("foo"){2} + assertEquals(2, a) - val b = data.getOrElse("foo"){3} - assertEquals(3, b) - assertEquals(0, data.size) - } + val b = data.getOrElse("foo"){3} + assertEquals(3, b) + assertEquals(0, data.size) + } - fun testGetOrPut() { - val a = data.getOrPut("foo"){2} - assertEquals(2, a) + fun testGetOrPut() { + val a = data.getOrPut("foo"){2} + assertEquals(2, a) - val b = data.getOrPut("foo"){3} - assertEquals(2, b) + val b = data.getOrPut("foo"){3} + assertEquals(2, b) - assertEquals(1, data.size()) - } + assertEquals(1, data.size()) + } - fun testSizeAndEmpty() { - assert{ data.empty } - assertEquals(data.size, 0) - } + fun testSizeAndEmpty() { + assertTrue{ data.empty } + assertEquals(data.size, 0) + } - fun testSetViaIndexOperators() { - val map = java.util.HashMap() - assert{ map.empty } - // TODO cannot use map.size due to compiler bug - assertEquals(map.size(), 0) + fun testSetViaIndexOperators() { + val map = java.util.HashMap() + assertTrue{ map.empty } + // TODO cannot use map.size due to compiler bug + assertEquals(map.size(), 0) - map["name"] = "James" + map["name"] = "James" - assert{ !map.empty } - // TODO cannot use map.size due to compiler bug - assertEquals(map.size(), 1) - assertEquals("James", map["name"]) - } + assertTrue{ !map.empty } + // TODO cannot use map.size due to compiler bug + assertEquals(map.size(), 1) + assertEquals("James", map["name"]) + } } diff --git a/testlib/test/MathTest.kt b/testlib/test/MathTest.kt index 93351c99eeb..434d0a55f5d 100644 --- a/testlib/test/MathTest.kt +++ b/testlib/test/MathTest.kt @@ -4,7 +4,7 @@ import std.math.* import java.math.BigInteger import java.math.BigDecimal -import stdhack.test.* +import kool.test.* class MathTest : TestSupport() { fun testBigInteger() { diff --git a/testlib/test/OldStdlibTest.kt b/testlib/test/OldStdlibTest.kt index e785f803f72..62b901555e8 100644 --- a/testlib/test/OldStdlibTest.kt +++ b/testlib/test/OldStdlibTest.kt @@ -3,7 +3,7 @@ package test.collections import std.* import std.io.* import std.util.* -import stdhack.test.* +import kool.test.* import java.util.* import java.io.* @@ -15,7 +15,7 @@ class OldStdlibTest() : TestSupport() { } fun testCollectionSize() { - assert { + assertTrue { Arrays.asList(0, 1, 2)?.size == 3 } } diff --git a/testlib/test/SetTest.kt b/testlib/test/SetTest.kt index 5d8eb61a4ad..cfa4ecd6abd 100644 --- a/testlib/test/SetTest.kt +++ b/testlib/test/SetTest.kt @@ -3,68 +3,68 @@ package test.collections import std.* import std.io.* import std.util.* -import stdhack.test.* +import kool.test.* import java.util.* class SetTest() : TestSupport() { - val data = hashSet("foo", "bar") + val data = hashSet("foo", "bar") - fun testAny() { - assert { - data.any{it.startsWith("f")} - } - assertNot { - data.any{it.startsWith("x")} - } - } - - fun testAll() { - assert { - data.all{it.length == 3} - } - assertNot { - data.all{(s: String) -> s.startsWith("b")} - } - } - - fun testFilter() { - val foo = data.filter{it.startsWith("f")}.toSet() - - assert { - foo.all{it.startsWith("f")} - } - assertEquals(1, foo.size) - assertEquals(hashSet("foo"), foo) - - assert("Filter on a Set should return a Set") { - foo is Set - } - } - - fun testFind() { - val x = data.find{it.startsWith("x")} - assertNull(x) - fails { - x.sure() + fun testAny() { + assertTrue { + data.any{it.startsWith("f")} + } + assertNot { + data.any{it.startsWith("x")} + } } - val f = data.find{it.startsWith("f")} - f.sure() - assertEquals("foo", f) - } - - fun testMap() { - /** - TODO compiler bug - we should be able to remove the explicit type on the function - http://youtrack.jetbrains.net/issue/KT-849 - */ - val lengths = data.map{(s: String) -> s.length} - assert { - lengths.all{it == 3} + fun testAll() { + assertTrue { + data.all{it.length == 3} + } + assertNot { + data.all{(s: String) -> s.startsWith("b")} + } + } + + fun testFilter() { + val foo = data.filter{it.startsWith("f")}.toSet() + + assertTrue { + foo.all{it.startsWith("f")} + } + assertEquals(1, foo.size) + assertEquals(hashSet("foo"), foo) + + assertTrue("Filter on a Set should return a Set") { + foo is Set + } + } + + fun testFind() { + val x = data.find{it.startsWith("x")} + assertNull(x) + fails { + x.sure() + } + + val f = data.find{it.startsWith("f")} + f.sure() + assertEquals("foo", f) + } + + fun testMap() { + /** + TODO compiler bug + we should be able to remove the explicit type on the function + http://youtrack.jetbrains.net/issue/KT-849 + */ + val lengths = data.map{(s: String) -> s.length} + assertTrue { + lengths.all{it == 3} + } + assertEquals(2, lengths.size) + assertEquals(arrayList(3, 3), lengths) } - assertEquals(2, lengths.size) - assertEquals(arrayList(3, 3), lengths) - } } diff --git a/testlib/test/StandardCollectionTest.kt b/testlib/test/StandardCollectionTest.kt index 8d8631c186a..7677873f0ef 100644 --- a/testlib/test/StandardCollectionTest.kt +++ b/testlib/test/StandardCollectionTest.kt @@ -1,7 +1,7 @@ package test.collections import std.* -import stdhack.test.* +import kool.test.* class StandardCollectionTest() : TestSupport() { @@ -13,7 +13,7 @@ class StandardCollectionTest() : TestSupport() { // TODO requires KT-924 to be implemented val data: Iterable = std.util.arrayList("foo", "bar") - assert { + assertTrue { data.any{it.startsWith("f")} } assertNot { diff --git a/testlib/test/StdLibIssuesTest.kt b/testlib/test/StdLibIssuesTest.kt index f8e6856a354..203031fc28d 100644 --- a/testlib/test/StdLibIssuesTest.kt +++ b/testlib/test/StdLibIssuesTest.kt @@ -2,7 +2,7 @@ package test.stdlib.issues import java.util.List import std.util.* -import stdhack.test.* +import kool.test.* private fun listDifference(first : List, second : List) : List { return first.filter{ !second.contains(it) }.toList() diff --git a/testlib/test/StringTest.kt b/testlib/test/StringTest.kt index 0dcf790b831..2e51feda4dd 100644 --- a/testlib/test/StringTest.kt +++ b/testlib/test/StringTest.kt @@ -1,7 +1,7 @@ package testString import std.io.* -import stdhack.test.* +import kool.test.* import junit.framework.* diff --git a/testlib/test/dom/DomBuilderTest.kt b/testlib/test/dom/DomBuilderTest.kt index d1045df18f6..5729a0f49d1 100644 --- a/testlib/test/dom/DomBuilderTest.kt +++ b/testlib/test/dom/DomBuilderTest.kt @@ -3,7 +3,7 @@ package test.dom import std.* import std.dom.* import std.util.* -import stdhack.test.* +import kool.test.* import org.w3c.dom.* class DomBuilderTest() : TestSupport() { @@ -11,7 +11,7 @@ class DomBuilderTest() : TestSupport() { fun testBuildDocument() { var doc = createDocument() - assert { + assertTrue { doc["grandchild"].isEmpty() } @@ -53,7 +53,7 @@ class DomBuilderTest() : TestSupport() { val root = doc.rootElement if (root != null) { - assert { + assertTrue { root.hasClass("bar") } diff --git a/testlib/test/dom/DomTest.kt b/testlib/test/dom/DomTest.kt index 1198b4f7011..1cf469464bc 100644 --- a/testlib/test/dom/DomTest.kt +++ b/testlib/test/dom/DomTest.kt @@ -2,7 +2,7 @@ package test.dom import std.* import std.dom.* -import stdhack.test.* +import kool.test.* import org.w3c.dom.* class DomTest() : TestSupport() { diff --git a/testlib/test/language/NullableCollectionsTest.kt b/testlib/test/language/NullableCollectionsTest.kt index 213ce88cd56..9fee997c321 100644 --- a/testlib/test/language/NullableCollectionsTest.kt +++ b/testlib/test/language/NullableCollectionsTest.kt @@ -2,7 +2,7 @@ package test.language import junit.framework.TestCase import java.util.Collection -import stdhack.test.* +import kool.test.* class NullableCollectionsTest : TestCase() { diff --git a/testlib/test/properties/PropertiesTest.kt b/testlib/test/properties/PropertiesTest.kt index 85c35121266..3b5f92c04f1 100644 --- a/testlib/test/properties/PropertiesTest.kt +++ b/testlib/test/properties/PropertiesTest.kt @@ -3,7 +3,7 @@ package test.properties import std.* import std.properties.* import std.util.* -import stdhack.test.* +import kool.test.* import java.util.* import junit.framework.TestCase