-
-
Save ekrich/bcde340a67bca52d4da90f64d296579a to your computer and use it in GitHub Desktop.
Port to JUnit of java.lang test for Scala Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/unit-tests/src/test/scala/java/lang/ClassSuite.scala b/unit-tests/src/test/scala/java/lang/ClassTest.scala | |
index f621555c..d3e6b031 100644 | |
--- a/unit-tests/src/test/scala/java/lang/ClassSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/ClassTest.scala | |
@@ -1,61 +1,65 @@ | |
package java.lang | |
-object ClassSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
- test("primitives have their own classes") { | |
- assert(classOf[scala.Boolean] != classOf[java.lang.Boolean]) | |
- assert(classOf[scala.Byte] != classOf[java.lang.Byte]) | |
- assert(classOf[scala.Char] != classOf[java.lang.Character]) | |
- assert(classOf[scala.Short] != classOf[java.lang.Short]) | |
- assert(classOf[scala.Int] != classOf[java.lang.Integer]) | |
- assert(classOf[scala.Long] != classOf[java.lang.Long]) | |
- assert(classOf[scala.Float] != classOf[java.lang.Float]) | |
- assert(classOf[scala.Double] != classOf[java.lang.Double]) | |
- assert(classOf[scala.Unit] != classOf[scala.runtime.BoxedUnit]) | |
+class ClassTest { | |
+ | |
+ @Test def primitivesHaveTheirOwnClasses(): Unit = { | |
+ assertTrue(classOf[scala.Boolean] != classOf[java.lang.Boolean]) | |
+ assertTrue(classOf[scala.Byte] != classOf[java.lang.Byte]) | |
+ assertTrue(classOf[scala.Char] != classOf[java.lang.Character]) | |
+ assertTrue(classOf[scala.Short] != classOf[java.lang.Short]) | |
+ assertTrue(classOf[scala.Int] != classOf[java.lang.Integer]) | |
+ assertTrue(classOf[scala.Long] != classOf[java.lang.Long]) | |
+ assertTrue(classOf[scala.Float] != classOf[java.lang.Float]) | |
+ assertTrue(classOf[scala.Double] != classOf[java.lang.Double]) | |
+ assertTrue(classOf[scala.Unit] != classOf[scala.runtime.BoxedUnit]) | |
} | |
- test("getComponentType") { | |
- assert(Array(false).getClass.getComponentType == classOf[scala.Boolean]) | |
- assert(Array('0').getClass.getComponentType == classOf[scala.Char]) | |
- assert(Array(0.toByte).getClass.getComponentType == classOf[scala.Byte]) | |
- assert(Array(0.toShort).getClass.getComponentType == classOf[scala.Short]) | |
- assert(Array(0).getClass.getComponentType == classOf[scala.Int]) | |
- assert(Array(0L).getClass.getComponentType == classOf[scala.Long]) | |
- assert(Array(0F).getClass.getComponentType == classOf[scala.Float]) | |
- assert(Array(0D).getClass.getComponentType == classOf[scala.Double]) | |
- assert( | |
+ @Test def getComponentType(): Unit = { | |
+ assertTrue(Array(false).getClass.getComponentType == classOf[scala.Boolean]) | |
+ assertTrue(Array('0').getClass.getComponentType == classOf[scala.Char]) | |
+ assertTrue(Array(0.toByte).getClass.getComponentType == classOf[scala.Byte]) | |
+ assertTrue( | |
+ Array(0.toShort).getClass.getComponentType == classOf[scala.Short]) | |
+ assertTrue(Array(0).getClass.getComponentType == classOf[scala.Int]) | |
+ assertTrue(Array(0L).getClass.getComponentType == classOf[scala.Long]) | |
+ assertTrue(Array(0F).getClass.getComponentType == classOf[scala.Float]) | |
+ assertTrue(Array(0D).getClass.getComponentType == classOf[scala.Double]) | |
+ assertTrue( | |
Array(new java.lang.Object).getClass.getComponentType == classOf[ | |
java.lang.Object]) | |
} | |
- test("isPrimitive") { | |
- assert(classOf[scala.Boolean].isPrimitive) | |
- assert(classOf[scala.Char].isPrimitive) | |
- assert(classOf[scala.Byte].isPrimitive) | |
- assert(classOf[scala.Short].isPrimitive) | |
- assert(classOf[scala.Int].isPrimitive) | |
- assert(classOf[scala.Long].isPrimitive) | |
- assert(classOf[scala.Float].isPrimitive) | |
- assert(classOf[scala.Double].isPrimitive) | |
- assert(classOf[scala.Unit].isPrimitive) | |
- assert(!classOf[java.lang.Object].isPrimitive) | |
- assert(!classOf[java.lang.String].isPrimitive) | |
+ @Test def isPrimitive(): Unit = { | |
+ assertTrue(classOf[scala.Boolean].isPrimitive) | |
+ assertTrue(classOf[scala.Char].isPrimitive) | |
+ assertTrue(classOf[scala.Byte].isPrimitive) | |
+ assertTrue(classOf[scala.Short].isPrimitive) | |
+ assertTrue(classOf[scala.Int].isPrimitive) | |
+ assertTrue(classOf[scala.Long].isPrimitive) | |
+ assertTrue(classOf[scala.Float].isPrimitive) | |
+ assertTrue(classOf[scala.Double].isPrimitive) | |
+ assertTrue(classOf[scala.Unit].isPrimitive) | |
+ assertFalse(classOf[java.lang.Object].isPrimitive) | |
+ assertFalse(classOf[java.lang.String].isPrimitive) | |
} | |
- test("isArray") { | |
- assert(classOf[Array[scala.Boolean]].isArray) | |
- assert(classOf[Array[scala.Char]].isArray) | |
- assert(classOf[Array[scala.Byte]].isArray) | |
- assert(classOf[Array[scala.Short]].isArray) | |
- assert(classOf[Array[scala.Int]].isArray) | |
- assert(classOf[Array[scala.Long]].isArray) | |
- assert(classOf[Array[scala.Float]].isArray) | |
- assert(classOf[Array[scala.Double]].isArray) | |
- assert(classOf[Array[scala.Unit]].isArray) | |
- assert(classOf[Array[java.lang.Object]].isArray) | |
- assert(classOf[Array[java.lang.String]].isArray) | |
- assert(!classOf[java.lang.Object].isArray) | |
- assert(!classOf[java.lang.String].isArray) | |
+ @Test def isArray(): Unit = { | |
+ assertTrue(classOf[Array[scala.Boolean]].isArray) | |
+ assertTrue(classOf[Array[scala.Char]].isArray) | |
+ assertTrue(classOf[Array[scala.Byte]].isArray) | |
+ assertTrue(classOf[Array[scala.Short]].isArray) | |
+ assertTrue(classOf[Array[scala.Int]].isArray) | |
+ assertTrue(classOf[Array[scala.Long]].isArray) | |
+ assertTrue(classOf[Array[scala.Float]].isArray) | |
+ assertTrue(classOf[Array[scala.Double]].isArray) | |
+ assertTrue(classOf[Array[scala.Unit]].isArray) | |
+ assertTrue(classOf[Array[java.lang.Object]].isArray) | |
+ assertTrue(classOf[Array[java.lang.String]].isArray) | |
+ assertFalse(classOf[java.lang.Object].isArray) | |
+ assertFalse(classOf[java.lang.String].isArray) | |
} | |
class A extends X | |
@@ -65,74 +69,74 @@ object ClassSuite extends tests.Suite { | |
trait Y extends X | |
trait Z | |
- test("isInstance") { | |
- assert(classOf[A].isInstance(new A)) | |
- assert(classOf[A].isInstance(new B)) | |
- assert(!classOf[A].isInstance(new C)) | |
- assert(!classOf[B].isInstance(new A)) | |
- assert(classOf[B].isInstance(new B)) | |
- assert(!classOf[B].isInstance(new C)) | |
- assert(!classOf[C].isInstance(new A)) | |
- assert(!classOf[C].isInstance(new B)) | |
- assert(classOf[C].isInstance(new C)) | |
- assert(classOf[X].isInstance(new A)) | |
- assert(classOf[X].isInstance(new B)) | |
- assert(!classOf[X].isInstance(new C)) | |
- assert(!classOf[Y].isInstance(new A)) | |
- assert(classOf[Y].isInstance(new B)) | |
- assert(!classOf[Y].isInstance(new C)) | |
- assert(!classOf[Z].isInstance(new A)) | |
- assert(!classOf[Z].isInstance(new B)) | |
- assert(!classOf[Z].isInstance(new C)) | |
+ @Test def isInstance(): Unit = { | |
+ assertTrue(classOf[A].isInstance(new A)) | |
+ assertTrue(classOf[A].isInstance(new B)) | |
+ assertFalse(classOf[A].isInstance(new C)) | |
+ assertFalse(classOf[B].isInstance(new A)) | |
+ assertTrue(classOf[B].isInstance(new B)) | |
+ assertFalse(classOf[B].isInstance(new C)) | |
+ assertFalse(classOf[C].isInstance(new A)) | |
+ assertFalse(classOf[C].isInstance(new B)) | |
+ assertTrue(classOf[C].isInstance(new C)) | |
+ assertTrue(classOf[X].isInstance(new A)) | |
+ assertTrue(classOf[X].isInstance(new B)) | |
+ assertFalse(classOf[X].isInstance(new C)) | |
+ assertFalse(classOf[Y].isInstance(new A)) | |
+ assertTrue(classOf[Y].isInstance(new B)) | |
+ assertFalse(classOf[Y].isInstance(new C)) | |
+ assertFalse(classOf[Z].isInstance(new A)) | |
+ assertFalse(classOf[Z].isInstance(new B)) | |
+ assertFalse(classOf[Z].isInstance(new C)) | |
} | |
- test("isAssignableFrom") { | |
- assert(classOf[A].isAssignableFrom(classOf[A])) | |
- assert(classOf[A].isAssignableFrom(classOf[B])) | |
- assert(!classOf[A].isAssignableFrom(classOf[C])) | |
- assert(!classOf[A].isAssignableFrom(classOf[X])) | |
- assert(!classOf[A].isAssignableFrom(classOf[Y])) | |
- assert(!classOf[A].isAssignableFrom(classOf[Z])) | |
- assert(!classOf[B].isAssignableFrom(classOf[A])) | |
- assert(classOf[B].isAssignableFrom(classOf[B])) | |
- assert(!classOf[B].isAssignableFrom(classOf[C])) | |
- assert(!classOf[B].isAssignableFrom(classOf[X])) | |
- assert(!classOf[B].isAssignableFrom(classOf[Y])) | |
- assert(!classOf[B].isAssignableFrom(classOf[Z])) | |
- assert(!classOf[C].isAssignableFrom(classOf[A])) | |
- assert(!classOf[C].isAssignableFrom(classOf[B])) | |
- assert(classOf[C].isAssignableFrom(classOf[C])) | |
- assert(!classOf[C].isAssignableFrom(classOf[X])) | |
- assert(!classOf[C].isAssignableFrom(classOf[Y])) | |
- assert(!classOf[C].isAssignableFrom(classOf[Z])) | |
- assert(classOf[X].isAssignableFrom(classOf[A])) | |
- assert(classOf[X].isAssignableFrom(classOf[B])) | |
- assert(!classOf[X].isAssignableFrom(classOf[C])) | |
- assert(classOf[X].isAssignableFrom(classOf[X])) | |
- assert(classOf[X].isAssignableFrom(classOf[Y])) | |
- assert(!classOf[X].isAssignableFrom(classOf[Z])) | |
- assert(!classOf[Y].isAssignableFrom(classOf[A])) | |
- assert(classOf[Y].isAssignableFrom(classOf[B])) | |
- assert(!classOf[Y].isAssignableFrom(classOf[C])) | |
- assert(!classOf[Y].isAssignableFrom(classOf[X])) | |
- assert(classOf[Y].isAssignableFrom(classOf[Y])) | |
- assert(!classOf[Y].isAssignableFrom(classOf[Z])) | |
- assert(!classOf[Z].isAssignableFrom(classOf[A])) | |
- assert(!classOf[Z].isAssignableFrom(classOf[B])) | |
- assert(!classOf[Z].isAssignableFrom(classOf[C])) | |
- assert(!classOf[Z].isAssignableFrom(classOf[X])) | |
- assert(!classOf[Z].isAssignableFrom(classOf[Y])) | |
- assert(classOf[Z].isAssignableFrom(classOf[Z])) | |
+ @Test def isAssignableFrom(): Unit = { | |
+ assertTrue(classOf[A].isAssignableFrom(classOf[A])) | |
+ assertTrue(classOf[A].isAssignableFrom(classOf[B])) | |
+ assertFalse(classOf[A].isAssignableFrom(classOf[C])) | |
+ assertFalse(classOf[A].isAssignableFrom(classOf[X])) | |
+ assertFalse(classOf[A].isAssignableFrom(classOf[Y])) | |
+ assertFalse(classOf[A].isAssignableFrom(classOf[Z])) | |
+ assertFalse(classOf[B].isAssignableFrom(classOf[A])) | |
+ assertTrue(classOf[B].isAssignableFrom(classOf[B])) | |
+ assertFalse(classOf[B].isAssignableFrom(classOf[C])) | |
+ assertFalse(classOf[B].isAssignableFrom(classOf[X])) | |
+ assertFalse(classOf[B].isAssignableFrom(classOf[Y])) | |
+ assertFalse(classOf[B].isAssignableFrom(classOf[Z])) | |
+ assertFalse(classOf[C].isAssignableFrom(classOf[A])) | |
+ assertFalse(classOf[C].isAssignableFrom(classOf[B])) | |
+ assertTrue(classOf[C].isAssignableFrom(classOf[C])) | |
+ assertFalse(classOf[C].isAssignableFrom(classOf[X])) | |
+ assertFalse(classOf[C].isAssignableFrom(classOf[Y])) | |
+ assertFalse(classOf[C].isAssignableFrom(classOf[Z])) | |
+ assertTrue(classOf[X].isAssignableFrom(classOf[A])) | |
+ assertTrue(classOf[X].isAssignableFrom(classOf[B])) | |
+ assertFalse(classOf[X].isAssignableFrom(classOf[C])) | |
+ assertTrue(classOf[X].isAssignableFrom(classOf[X])) | |
+ assertTrue(classOf[X].isAssignableFrom(classOf[Y])) | |
+ assertFalse(classOf[X].isAssignableFrom(classOf[Z])) | |
+ assertFalse(classOf[Y].isAssignableFrom(classOf[A])) | |
+ assertTrue(classOf[Y].isAssignableFrom(classOf[B])) | |
+ assertFalse(classOf[Y].isAssignableFrom(classOf[C])) | |
+ assertFalse(classOf[Y].isAssignableFrom(classOf[X])) | |
+ assertTrue(classOf[Y].isAssignableFrom(classOf[Y])) | |
+ assertFalse(classOf[Y].isAssignableFrom(classOf[Z])) | |
+ assertFalse(classOf[Z].isAssignableFrom(classOf[A])) | |
+ assertFalse(classOf[Z].isAssignableFrom(classOf[B])) | |
+ assertFalse(classOf[Z].isAssignableFrom(classOf[C])) | |
+ assertFalse(classOf[Z].isAssignableFrom(classOf[X])) | |
+ assertFalse(classOf[Z].isAssignableFrom(classOf[Y])) | |
+ assertTrue(classOf[Z].isAssignableFrom(classOf[Z])) | |
} | |
- test("toString") { | |
- assert(classOf[java.lang.Class[_]].toString == "class java.lang.Class") | |
- assert( | |
+ @Test def testToString(): Unit = { | |
+ assertTrue(classOf[java.lang.Class[_]].toString == "class java.lang.Class") | |
+ assertTrue( | |
classOf[java.lang.Runnable].toString == "interface java.lang.Runnable") | |
} | |
- test("isInterface") { | |
- assert(!classOf[java.lang.Class[_]].isInterface) | |
- assert(classOf[java.lang.Runnable].isInterface) | |
+ @Test def isInterface(): Unit = { | |
+ assertFalse(classOf[java.lang.Class[_]].isInterface) | |
+ assertTrue(classOf[java.lang.Runnable].isInterface) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/IntegerSuite.scala b/unit-tests/src/test/scala/java/lang/IntegerTest.scala | |
index 04290c8d..932de6b8 100644 | |
--- a/unit-tests/src/test/scala/java/lang/IntegerSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/IntegerTest.scala | |
@@ -1,6 +1,11 @@ | |
package java.lang | |
-object IntegerSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class IntegerTest { | |
val signedMaxValue = Integer.MAX_VALUE | |
val signedMaxValueText = "2147483647" | |
val signedMinValue = Integer.MIN_VALUE | |
@@ -13,125 +18,129 @@ object IntegerSuite extends tests.Suite { | |
val unsignedMaxValueText = "4294967295" | |
val unsignedMaxPlusOneText = "4294967296" | |
- test("parseInt") { | |
+ @Test def parseInt(): Unit = { | |
import Integer.{parseInt => parse} | |
- assert(parse("-1") == -1) | |
- assert(parse("+1") == 1) | |
- assert(parse("1") == 1) | |
- assert(parse("-123") == -123) | |
- assert(parse("+123") == 123) | |
- assert(parse("123") == 123) | |
- assert(parse("-100", 2) == -4) | |
- assert(parse("+100", 2) == 4) | |
- assert(parse("100", 2) == 4) | |
- assert(parse("-0") == 0) | |
- assert(parse("+0") == 0) | |
- assert(parse("00") == 0) | |
- assert(parse(signedMaxValueText) == signedMaxValue) | |
- assert(parse(signedMinValueText) == signedMinValue) | |
- | |
- assertThrows[NumberFormatException](parse(null)) | |
- assertThrows[NumberFormatException](parse("+")) | |
- assertThrows[NumberFormatException](parse("-")) | |
- assertThrows[NumberFormatException](parse("")) | |
- assertThrows[NumberFormatException](parse("123", Character.MIN_RADIX - 1)) | |
- assertThrows[NumberFormatException](parse("123", Character.MAX_RADIX + 1)) | |
- assertThrows[NumberFormatException](parse("123a", 10)) | |
- assertThrows[NumberFormatException](parse(signedMinMinusOneText)) | |
- assertThrows[NumberFormatException](parse(signedMaxPlusOneText)) | |
+ assertTrue(parse("-1") == -1) | |
+ assertTrue(parse("+1") == 1) | |
+ assertTrue(parse("1") == 1) | |
+ assertTrue(parse("-123") == -123) | |
+ assertTrue(parse("+123") == 123) | |
+ assertTrue(parse("123") == 123) | |
+ assertTrue(parse("-100", 2) == -4) | |
+ assertTrue(parse("+100", 2) == 4) | |
+ assertTrue(parse("100", 2) == 4) | |
+ assertTrue(parse("-0") == 0) | |
+ assertTrue(parse("+0") == 0) | |
+ assertTrue(parse("00") == 0) | |
+ assertTrue(parse(signedMaxValueText) == signedMaxValue) | |
+ assertTrue(parse(signedMinValueText) == signedMinValue) | |
+ | |
+ assertThrows(classOf[NumberFormatException], parse(null)) | |
+ assertThrows(classOf[NumberFormatException], parse("+")) | |
+ assertThrows(classOf[NumberFormatException], parse("-")) | |
+ assertThrows(classOf[NumberFormatException], parse("")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MIN_RADIX - 1)) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MAX_RADIX + 1)) | |
+ assertThrows(classOf[NumberFormatException], parse("123a", 10)) | |
+ assertThrows(classOf[NumberFormatException], parse(signedMinMinusOneText)) | |
+ assertThrows(classOf[NumberFormatException], parse(signedMaxPlusOneText)) | |
} | |
- test("parseUnsignedInt") { | |
+ @Test def parseUnsignedInt(): Unit = { | |
import Integer.{parseUnsignedInt => parse} | |
- assert(parse("1") == 1) | |
- assert(parse("+1") == 1) | |
- assert(parse("0") == 0) | |
- assert(parse("00") == 0) | |
- assert(parse("+100", 2) == 4) | |
- assert(parse("100", 2) == 4) | |
- assert(parse(unsignedMaxValueText) == unsignedMaxValue) | |
- | |
- assertThrows[NumberFormatException](parse(null)) | |
- assertThrows[NumberFormatException](parse("+")) | |
- assertThrows[NumberFormatException](parse("-")) | |
- assertThrows[NumberFormatException](parse("")) | |
- assertThrows[NumberFormatException](parse("-1")) | |
- assertThrows[NumberFormatException](parse("123", Character.MIN_RADIX - 1)) | |
- assertThrows[NumberFormatException](parse("123", Character.MAX_RADIX + 1)) | |
- assertThrows[NumberFormatException](parse("123a", 10)) | |
- assertThrows[NumberFormatException](parse(unsignedMaxPlusOneText)) | |
+ assertTrue(parse("1") == 1) | |
+ assertTrue(parse("+1") == 1) | |
+ assertTrue(parse("0") == 0) | |
+ assertTrue(parse("00") == 0) | |
+ assertTrue(parse("+100", 2) == 4) | |
+ assertTrue(parse("100", 2) == 4) | |
+ assertTrue(parse(unsignedMaxValueText) == unsignedMaxValue) | |
+ | |
+ assertThrows(classOf[NumberFormatException], parse(null)) | |
+ assertThrows(classOf[NumberFormatException], parse("+")) | |
+ assertThrows(classOf[NumberFormatException], parse("-")) | |
+ assertThrows(classOf[NumberFormatException], parse("")) | |
+ assertThrows(classOf[NumberFormatException], parse("-1")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MIN_RADIX - 1)) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MAX_RADIX + 1)) | |
+ assertThrows(classOf[NumberFormatException], parse("123a", 10)) | |
+ assertThrows(classOf[NumberFormatException], parse(unsignedMaxPlusOneText)) | |
val octalMulOverflow = "137777777770" | |
// in binary: | |
// octalMulOverflow: 01011111111111111111111111111111000 | |
// max unsigned: 00011111111111111111111111111111111 | |
- assertThrows[NumberFormatException](parse(octalMulOverflow, 8)) | |
+ assertThrows(classOf[NumberFormatException], parse(octalMulOverflow, 8)) | |
} | |
- test("toString") { | |
+ @Test def testToString(): Unit = { | |
import java.lang.Integer.{toString => toStr} | |
- assert(toStr(0) == "0") | |
- assert(toStr(1) == "1") | |
- assert(toStr(12) == "12") | |
- assert(toStr(123) == "123") | |
- assert(toStr(1234) == "1234") | |
- assert(toStr(12345) == "12345") | |
- assert(toStr(10) == "10") | |
- assert(toStr(100) == "100") | |
- assert(toStr(1000) == "1000") | |
- assert(toStr(10000) == "10000") | |
- assert(toStr(100000) == "100000") | |
- assert(toStr(101010) == "101010") | |
- assert(toStr(111111) == "111111") | |
- assert(toStr(-1) == "-1") | |
- assert(toStr(-12) == "-12") | |
- assert(toStr(-123) == "-123") | |
- assert(toStr(-1234) == "-1234") | |
- assert(toStr(-12345) == "-12345") | |
- assert(toStr(signedMaxValue) == signedMaxValueText) | |
- assert(toStr(signedMinValue) == signedMinValueText) | |
+ assertTrue(toStr(0) == "0") | |
+ assertTrue(toStr(1) == "1") | |
+ assertTrue(toStr(12) == "12") | |
+ assertTrue(toStr(123) == "123") | |
+ assertTrue(toStr(1234) == "1234") | |
+ assertTrue(toStr(12345) == "12345") | |
+ assertTrue(toStr(10) == "10") | |
+ assertTrue(toStr(100) == "100") | |
+ assertTrue(toStr(1000) == "1000") | |
+ assertTrue(toStr(10000) == "10000") | |
+ assertTrue(toStr(100000) == "100000") | |
+ assertTrue(toStr(101010) == "101010") | |
+ assertTrue(toStr(111111) == "111111") | |
+ assertTrue(toStr(-1) == "-1") | |
+ assertTrue(toStr(-12) == "-12") | |
+ assertTrue(toStr(-123) == "-123") | |
+ assertTrue(toStr(-1234) == "-1234") | |
+ assertTrue(toStr(-12345) == "-12345") | |
+ assertTrue(toStr(signedMaxValue) == signedMaxValueText) | |
+ assertTrue(toStr(signedMinValue) == signedMinValueText) | |
} | |
- test("toUnsignedString") { | |
+ @Test def toUnsignedString(): Unit = { | |
import java.lang.Integer.{toUnsignedString => toStr} | |
- assert(toStr(0) == "0") | |
- assert(toStr(1) == "1") | |
- assert(toStr(12) == "12") | |
- assert(toStr(123) == "123") | |
- assert(toStr(1234) == "1234") | |
- assert(toStr(12345) == "12345") | |
- assert(toStr(-1) == "4294967295") | |
- assert(toStr(-12) == "4294967284") | |
- assert(toStr(-123) == "4294967173") | |
- assert(toStr(-1234) == "4294966062") | |
- assert(toStr(-12345) == "4294954951") | |
- assert(toStr(unsignedMaxValue) == unsignedMaxValueText) | |
+ assertTrue(toStr(0) == "0") | |
+ assertTrue(toStr(1) == "1") | |
+ assertTrue(toStr(12) == "12") | |
+ assertTrue(toStr(123) == "123") | |
+ assertTrue(toStr(1234) == "1234") | |
+ assertTrue(toStr(12345) == "12345") | |
+ assertTrue(toStr(-1) == "4294967295") | |
+ assertTrue(toStr(-12) == "4294967284") | |
+ assertTrue(toStr(-123) == "4294967173") | |
+ assertTrue(toStr(-1234) == "4294966062") | |
+ assertTrue(toStr(-12345) == "4294954951") | |
+ assertTrue(toStr(unsignedMaxValue) == unsignedMaxValueText) | |
} | |
- test("equals") { | |
- assert(new Integer(0) == new Integer(0)) | |
- assert(new Integer(1) == new Integer(1)) | |
- assert(new Integer(-1) == new Integer(-1)) | |
- assert(new Integer(123) == new Integer(123)) | |
- assert(new Integer(Integer.MAX_VALUE) == new Integer(Integer.MAX_VALUE)) | |
- assert(new Integer(Integer.MIN_VALUE) == new Integer(Integer.MIN_VALUE)) | |
+ @Test def testEquals(): Unit = { | |
+ assertTrue(new Integer(0) == new Integer(0)) | |
+ assertTrue(new Integer(1) == new Integer(1)) | |
+ assertTrue(new Integer(-1) == new Integer(-1)) | |
+ assertTrue(new Integer(123) == new Integer(123)) | |
+ assertTrue(new Integer(Integer.MAX_VALUE) == new Integer(Integer.MAX_VALUE)) | |
+ assertTrue(new Integer(Integer.MIN_VALUE) == new Integer(Integer.MIN_VALUE)) | |
} | |
- test("highestOneBit") { | |
- assert(Integer.highestOneBit(1) == 1) | |
- assert(Integer.highestOneBit(2) == 2) | |
- assert(Integer.highestOneBit(3) == 2) | |
- assert(Integer.highestOneBit(4) == 4) | |
- assert(Integer.highestOneBit(5) == 4) | |
- assert(Integer.highestOneBit(6) == 4) | |
- assert(Integer.highestOneBit(7) == 4) | |
- assert(Integer.highestOneBit(8) == 8) | |
- assert(Integer.highestOneBit(9) == 8) | |
- assert(Integer.highestOneBit(63) == 32) | |
- assert(Integer.highestOneBit(64) == 64) | |
+ @Test def highestOneBit(): Unit = { | |
+ assertTrue(Integer.highestOneBit(1) == 1) | |
+ assertTrue(Integer.highestOneBit(2) == 2) | |
+ assertTrue(Integer.highestOneBit(3) == 2) | |
+ assertTrue(Integer.highestOneBit(4) == 4) | |
+ assertTrue(Integer.highestOneBit(5) == 4) | |
+ assertTrue(Integer.highestOneBit(6) == 4) | |
+ assertTrue(Integer.highestOneBit(7) == 4) | |
+ assertTrue(Integer.highestOneBit(8) == 8) | |
+ assertTrue(Integer.highestOneBit(9) == 8) | |
+ assertTrue(Integer.highestOneBit(63) == 32) | |
+ assertTrue(Integer.highestOneBit(64) == 64) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/MathSuite.scala b/unit-tests/src/test/scala/java/lang/MathTest.scala | |
index edd575de..c68904c9 100644 | |
--- a/unit-tests/src/test/scala/java/lang/MathSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/MathTest.scala | |
@@ -1,111 +1,116 @@ | |
package java.lang | |
-object MathSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+class MathTest { | |
// Max() | |
- test("max with NaN arguments") { | |
+ @Test def maxWithNanArguments(): Unit = { | |
val a = 123.123d | |
val b = 456.456d | |
- assert(Math.max(Double.NaN, b).isNaN, "Double.NaN as first argument") | |
- assert(Math.max(a, Double.NaN).isNaN, "Double.NaN as second argument") | |
+ assertTrue("Double.NaN as first argument", Math.max(Double.NaN, b).isNaN) | |
+ assertTrue("Double.NaN as second argument", Math.max(a, Double.NaN).isNaN) | |
- assert(Math.max(Float.NaN, b.toFloat).isNaN, "Float.NaN as first argument") | |
- assert(Math.max(a, Float.NaN).isNaN, "Float.NaN as second argument") | |
+ assertTrue("Float.NaN as first argument", | |
+ Math.max(Float.NaN, b.toFloat).isNaN) | |
+ assertTrue("Float.NaN as second argument", Math.max(a, Float.NaN).isNaN) | |
} | |
- test("max a > b") { | |
+ @Test def maxAlphaGreaterThanBeta(): Unit = { | |
val a = 578.910d | |
val b = 456.456d | |
- assert(Math.max(a, b) == a, "Double") | |
- assert(Math.max(a.toFloat, b.toFloat) == a.toFloat, "Float") | |
- assert(Math.max(a.toInt, b.toInt) == a.toInt, "Int") | |
- assert(Math.max(a.toLong, b.toLong) == a.toLong, "Long") | |
+ assertTrue("Double", Math.max(a, b) == a) | |
+ assertTrue("Float", Math.max(a.toFloat, b.toFloat) == a.toFloat) | |
+ assertTrue("Int", Math.max(a.toInt, b.toInt) == a.toInt) | |
+ assertTrue("Long", Math.max(a.toLong, b.toLong) == a.toLong) | |
} | |
- test("max a == b") { | |
+ @Test def maxAlphaEqualEqualBeta(): Unit = { | |
val a = 576528 | |
val b = a | |
- assert(Math.max(a, b) == a, "Double") | |
- assert(Math.max(a.toFloat, b.toFloat) == a.toFloat, "Float") | |
- assert(Math.max(a.toInt, b.toInt) == a.toInt, "Int") | |
- assert(Math.max(a.toLong, b.toLong) == a.toLong, "Long") | |
+ assertTrue("Double", Math.max(a, b) == a) | |
+ assertTrue("Float", Math.max(a.toFloat, b.toFloat) == a.toFloat) | |
+ assertTrue("Int", Math.max(a.toInt, b.toInt) == a.toInt) | |
+ assertTrue("Long", Math.max(a.toLong, b.toLong) == a.toLong) | |
} | |
- test("max a < b") { | |
+ @Test def maxAlphaLessThanBeta(): Unit = { | |
val a = 123.123d | |
val b = 456.456d | |
- assert(Math.max(a, b) == b, "Double") | |
- assert(Math.max(a.toFloat, b.toFloat) == b.toFloat, "Float") | |
- assert(Math.max(a.toInt, b.toInt) == b.toInt, "Int") | |
- assert(Math.max(a.toLong, b.toLong) == b.toLong, "Long") | |
+ assertTrue("Double", Math.max(a, b) == b) | |
+ assertTrue("Float", Math.max(a.toFloat, b.toFloat) == b.toFloat) | |
+ assertTrue("Int", Math.max(a.toInt, b.toInt) == b.toInt) | |
+ assertTrue("Long", Math.max(a.toLong, b.toLong) == b.toLong) | |
} | |
// Min() | |
- test("min with NaN arguments") { | |
+ @Test def minWithNanArguments(): Unit = { | |
val a = 773.211d | |
val b = 843.531d | |
- assert(Math.max(Double.NaN, b).isNaN, "Double.NaN as first argument") | |
- assert(Math.max(a, Double.NaN).isNaN, "Double.NaN as second argument") | |
+ assertTrue("Double.NaN as first argument", Math.max(Double.NaN, b).isNaN) | |
+ assertTrue("Double.NaN as second argument", Math.max(a, Double.NaN).isNaN) | |
- assert(Math.max(Float.NaN, b.toFloat).isNaN, "Float.NaN as first argument") | |
- assert(Math.max(a, Float.NaN).isNaN, "Float.NaN as second argument") | |
+ assertTrue("Float.NaN as first argument", | |
+ Math.max(Float.NaN, b.toFloat).isNaN) | |
+ assertTrue("Float.NaN as second argument", Math.max(a, Float.NaN).isNaN) | |
} | |
- test("min a > b") { | |
+ @Test def minAlphaGreaterThanBeta(): Unit = { | |
val a = 949.538d | |
val b = 233.411d | |
- assert(Math.min(a, b) == b, "Double") | |
- assert(Math.min(a.toFloat, b.toFloat) == b.toFloat, "Float") | |
- assert(Math.min(a.toInt, b.toInt) == b.toInt, "Int") | |
- assert(Math.min(a.toLong, b.toLong) == b.toLong, "Long") | |
+ assertTrue("Double", Math.min(a, b) == b) | |
+ assertTrue("Float", Math.min(a.toFloat, b.toFloat) == b.toFloat) | |
+ assertTrue("Int", Math.min(a.toInt, b.toInt) == b.toInt) | |
+ assertTrue("Long", Math.min(a.toLong, b.toLong) == b.toLong) | |
} | |
- test("min a == b") { | |
+ @Test def minAlphaEqualEqualBeta(): Unit = { | |
val a = 553.838d | |
val b = a | |
- assert(Math.min(a, b) == b, "Double") | |
- assert(Math.min(a.toFloat, b.toFloat) == b.toFloat, "Float") | |
- assert(Math.min(a.toInt, b.toInt) == b.toInt, "Int") | |
- assert(Math.min(a.toLong, b.toLong) == b.toLong, "Long") | |
+ assertTrue("Double", Math.min(a, b) == b) | |
+ assertTrue("Float", Math.min(a.toFloat, b.toFloat) == b.toFloat) | |
+ assertTrue("Int", Math.min(a.toInt, b.toInt) == b.toInt) | |
+ assertTrue("Long", Math.min(a.toLong, b.toLong) == b.toLong) | |
} | |
- test("min a < b") { | |
+ @Test def minAlphaLessThanBeta(): Unit = { | |
val a = 312.966d | |
val b = 645.521d | |
- assert(Math.min(a, b) == a, "Double") | |
- assert(Math.min(a.toFloat, b.toFloat) == a.toFloat, "Float") | |
- assert(Math.min(a.toInt, b.toInt) == a.toInt, "Int") | |
- assert(Math.min(a.toLong, b.toLong) == a.toLong, "Long") | |
+ assertTrue("Double", Math.min(a, b) == a) | |
+ assertTrue("Float", Math.min(a.toFloat, b.toFloat) == a.toFloat) | |
+ assertTrue("Int", Math.min(a.toInt, b.toInt) == a.toInt) | |
+ assertTrue("Long", Math.min(a.toLong, b.toLong) == a.toLong) | |
} | |
// round() | |
- test("round(Double) - special values") { | |
+ @Test def roundDoubleSpecialValues(): Unit = { | |
- assert(Math.round(Double.NaN) == 0L, "round(NaN) != 0L") | |
+ assertTrue("round(NaN) != 0L", Math.round(Double.NaN) == 0L) | |
// value d as reported in issue #1071 | |
val dTooLarge: Double = 4228438087383875356545203991520.000000d | |
val roundedTooLarge: Long = Math.round(dTooLarge) | |
val expectedTooLarge: Long = scala.Long.MaxValue | |
- assert(roundedTooLarge == expectedTooLarge, | |
- s"${roundedTooLarge} != ${expectedTooLarge}" + | |
- " when Double > Long.MaxValue") | |
+ assertTrue(s"${roundedTooLarge} != ${expectedTooLarge}" + | |
+ " when Double > Long.MaxValue", | |
+ roundedTooLarge == expectedTooLarge) | |
val roundedTooNegative: Long = Math.round(-1.0 * dTooLarge) | |
val expectedTooNegative: Long = scala.Long.MinValue | |
- assert(roundedTooNegative == expectedTooNegative, | |
- s"${roundedTooNegative} != ${expectedTooNegative}" + | |
- " when Double < Long.MinValue") | |
+ assertTrue(s"${roundedTooNegative} != ${expectedTooNegative}" + | |
+ " when Double < Long.MinValue", | |
+ roundedTooNegative == expectedTooNegative) | |
} | |
- test("round(Double) - ties rounding towards +Infinity") { | |
+ @Test def roundDoubleTiesRoundingTowardsPlusInfinity(): Unit = { | |
case class TestPoint(value: Double, expected: Long) | |
@@ -164,33 +169,33 @@ object MathSuite extends tests.Suite { | |
val result: Long = math.round(v) | |
val expected: Long = testPoint.expected | |
- assert(result == testPoint.expected, | |
- s"round(${v}) result: ${result} != expected: ${expected}") | |
+ assertTrue(s"round(${v}) result: ${result} != expected: ${expected}", | |
+ result == testPoint.expected) | |
} | |
} | |
} | |
- test("round(Float) - special values") { | |
+ @Test def roundFloatSpecialValues(): Unit = { | |
- assert(Math.round(Float.NaN) == 0, "round(NaN) != 0") | |
+ assertTrue("round(NaN) != 0", Math.round(Float.NaN) == 0) | |
val fTooLarge: Float = scala.Float.MaxValue | |
val roundedTooLarge: Int = Math.round(fTooLarge) | |
val expectedTooLarge: Int = scala.Int.MaxValue | |
- assert(roundedTooLarge == expectedTooLarge, | |
- s"${roundedTooLarge} != ${expectedTooLarge}" + | |
- " when Float > Int.MaxValue") | |
+ assertTrue(s"${roundedTooLarge} != ${expectedTooLarge}" + | |
+ " when Float > Int.MaxValue", | |
+ roundedTooLarge == expectedTooLarge) | |
val roundedTooNegative: Int = Math.round(scala.Float.MinValue) | |
val expectedTooNegative: Int = scala.Int.MinValue | |
- assert(roundedTooNegative == expectedTooNegative, | |
- s"${roundedTooNegative} != ${expectedTooNegative}" + | |
- " when Float < Int.MinValue") | |
+ assertTrue(s"${roundedTooNegative} != ${expectedTooNegative}" + | |
+ " when Float < Int.MinValue", | |
+ roundedTooNegative == expectedTooNegative) | |
} | |
- test("round(Float) - ties rounding towards +Infinity") { | |
+ @Test def roundFloatTiesRoundingTowardsPlusInfinity(): Unit = { | |
case class TestPoint(value: Float, expected: Int) | |
@@ -246,8 +251,8 @@ object MathSuite extends tests.Suite { | |
val result: Int = math.round(v) | |
val expected: Int = testPoint.expected | |
- assert(result == testPoint.expected, | |
- s"round(${v}) result: ${result} != expected: ${expected}") | |
+ assertTrue(s"round(${v}) result: ${result} != expected: ${expected}", | |
+ result == testPoint.expected) | |
} | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/SystemSuite.scala b/unit-tests/src/test/scala/java/lang/SystemTest.scala | |
index 74c28026..c240dba3 100644 | |
--- a/unit-tests/src/test/scala/java/lang/SystemSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/SystemTest.scala | |
@@ -1,7 +1,10 @@ | |
package java.lang | |
-object SystemSuite extends tests.Suite { | |
- test("System.nanoTime is monotonically increasing") { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+class SystemTest { | |
+ @Test def systemNanoTimeIsMonotonicallyIncreasing(): Unit = { | |
var t0 = 0L | |
var t1 = 0L | |
@@ -19,7 +22,7 @@ object SystemSuite extends tests.Suite { | |
assert(startTime - endTime < 0L) | |
} | |
- test("System.getenv should contain known env variables") { | |
+ @Test def systemGetenvShouldContainKnownEnvVariables(): Unit = { | |
assert(System.getenv().containsKey("HOME")) | |
assert(System.getenv().get("USER") == "scala-native") | |
assert(System.getenv().get("SCALA_NATIVE_ENV_WITH_EQUALS") == "1+1=2") | |
@@ -31,14 +34,15 @@ object SystemSuite extends tests.Suite { | |
.get("SCALA_NATIVE_ENV_WITH_UNICODE") == 0x2192.toChar.toString) | |
} | |
- test("System.getenv(key) should read known env variables") { | |
+ @Test def systemGetenvKeyShouldReadKnownEnvVariables(): Unit = { | |
assert(System.getenv("USER") == "scala-native") | |
assert(System.getenv("SCALA_NATIVE_ENV_WITH_EQUALS") == "1+1=2") | |
assert(System.getenv("SCALA_NATIVE_ENV_WITHOUT_VALUE") == "") | |
assert(System.getenv("SCALA_NATIVE_ENV_THAT_DOESNT_EXIST") == null) | |
} | |
- test("System.currentTimeMillis seconds should approximately == C time()") { | |
+ @Test def systemCurrentTimeMillisSecondsShouldApproximatePosixTime()() | |
+ : Unit = { | |
// This is a coarse-grain sanity check, primarily to ensure that 64 bit | |
// math is being done on 32 bit systems. Only seconds are considered. | |
@@ -64,11 +68,11 @@ object SystemSuite extends tests.Suite { | |
assert(delta <= tolerance) | |
} | |
- test("Property user.home should be set") { | |
+ @Test def propertyUserHomeShouldBeSet(): Unit = { | |
assertEquals(System.getProperty("user.home"), System.getenv("HOME")) | |
} | |
- test("Property user.dir should be set") { | |
+ @Test def propertyUserDirShouldBeSet(): Unit = { | |
assertEquals(System.getProperty("user.dir"), | |
System.getenv("SCALA_NATIVE_USER_DIR")) | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/StringSuite.scala b/unit-tests/src/test/scala/java/lang/StringTest.scala | |
index c373d420..e2001d9e 100644 | |
--- a/unit-tests/src/test/scala/java/lang/StringSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/StringTest.scala | |
@@ -1,157 +1,158 @@ | |
package java.lang | |
+ | |
import java.nio.charset.{Charset, StandardCharsets} | |
-object StringSuite extends tests.Suite { | |
+import org.junit.Ignore | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
- test("String(Array[Byte], Int, Int, String) with null encoding") { | |
- assertThrows[java.lang.NullPointerException] { | |
- new String("I don't like nulls".getBytes, 0, 3, null: String) | |
- } | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class StringTest { | |
+ | |
+ @Test def stringArrayByteIntIntStringWithNullEncoding(): Unit = { | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ new String("I don't like nulls".getBytes, 0, 3, null: String)) | |
} | |
- test("String(Array[Byte], Int, Int, String) with unsupported encoding") { | |
- assertThrows[java.io.UnsupportedEncodingException] { | |
- new String("Pacem in terris".getBytes, 0, 3, "unsupported encoding") | |
- } | |
+ @Test def stringArrayByteIntIntStringWithUnsupportedEncoding(): Unit = { | |
+ assertThrows( | |
+ classOf[java.io.UnsupportedEncodingException], | |
+ new String("Pacem in terris".getBytes, 0, 3, "unsupported encoding")) | |
} | |
- test("String(Array[Byte], String) with null encoding") { | |
- assertThrows[java.lang.NullPointerException] { | |
- new String("Nulls are just as bad".getBytes, null: String) | |
- } | |
+ @Test def stringArrayByteStringWithNullEncoding(): Unit = { | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ new String("Nulls are just as bad".getBytes, null: String)) | |
} | |
- test("String(Array[Byte], String) with unsupported encoding") { | |
- assertThrows[java.io.UnsupportedEncodingException] { | |
- new String("to people of goodwill.".getBytes, "unsupported encoding") | |
- } | |
+ @Test def stringArrayByteStringWithUnsupportedEncoding(): Unit = { | |
+ assertThrows( | |
+ classOf[java.io.UnsupportedEncodingException], | |
+ new String("to people of goodwill.".getBytes, "unsupported encoding")) | |
} | |
- test("String(Array[Byte], start, length) with invalid start or length") { | |
+ @Test def stringArrayByteStartLengthWithInvalidStartOrLength(): Unit = { | |
val chars: Array[Char] = Array('a', 'b', 'c') | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- new String(chars, -1, chars.length) // invalid start | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ new String(chars, -1, chars.length) // invalid start | |
+ ) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- new String(chars, 0, chars.length + 1) // invalid length | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ new String(chars, 0, chars.length + 1) // invalid length | |
+ ) | |
} | |
- test("String(Array[Int], offset, count) with invalid offset or count") { | |
+ @Test def stringArrayIntOffsetCountWithInvalidOffsetOrCount(): Unit = { | |
val codePoints = Array[Int](235, 872, 700, 298) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- new String(codePoints, -1, codePoints.length) // invalid offset | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ new String(codePoints, -1, codePoints.length) // invalid offset | |
+ ) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
+ assertThrows( | |
+ classOf[java.lang.StringIndexOutOfBoundsException], | |
new String(codePoints, 0, codePoints.length + 1) // invalid length | |
- } | |
+ ) | |
} | |
- test("+") { | |
- assert("big 5" == "big " + 5.toByte) | |
- assert("big 5" == "big " + 5.toShort) | |
- assert("big 5" == "big " + 5) | |
- assert("big 5" == "big " + 5L) | |
- assert("5 big" == 5.toByte + " big") | |
- assert("5 big" == 5.toShort + " big") | |
- assert("5 big" == 5 + " big") | |
- assert("5 big" == 5L + " big") | |
- assert("foo" == "foo" + "") | |
- assert("foo" == "" + "foo") | |
- assert("foobar" == "foo" + "bar") | |
- assert("foobarbaz" == "foo" + "bar" + "baz") | |
+ @Test def plus(): Unit = { | |
+ assertTrue("big 5" == "big " + 5.toByte) | |
+ assertTrue("big 5" == "big " + 5.toShort) | |
+ assertTrue("big 5" == "big " + 5) | |
+ assertTrue("big 5" == "big " + 5L) | |
+ assertTrue("5 big" == 5.toByte + " big") | |
+ assertTrue("5 big" == 5.toShort + " big") | |
+ assertTrue("5 big" == 5 + " big") | |
+ assertTrue("5 big" == 5L + " big") | |
+ assertTrue("foo" == "foo" + "") | |
+ assertTrue("foo" == "" + "foo") | |
+ assertTrue("foobar" == "foo" + "bar") | |
+ assertTrue("foobarbaz" == "foo" + "bar" + "baz") | |
} | |
- test("codePointAt(index) with invalid index") { | |
+ @Test def codePointAtIndexWithInvalidIndex(): Unit = { | |
val data = "When in the Course" | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- data.codePointAt(-1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ data.codePointAt(-1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- data.codePointAt(data.length + 1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ data.codePointAt(data.length + 1)) | |
} | |
- test("codePointBefore(index) with invalid index") { | |
+ @Test def codePointBeforeIndexWithInvalidIndex(): Unit = { | |
val data = "of human events" | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- data.codePointBefore(-1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ data.codePointBefore(-1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- // Careful here, +1 is valid +2 is not | |
- data.codePointBefore(data.length + 2) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ // Careful here, +1 is valid +2 is not | |
+ data.codePointBefore(data.length + 2)) | |
} | |
- test("codePointCount(beginIndex, endIndex) with invalid begin | end index") { | |
+ @Test def codePointCountBeginIndexEndIndexWithInvalidBeginOrEndIndex() | |
+ : Unit = { | |
val data = "it becomes necessary" | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- data.codePointCount(-1, data.length) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ data.codePointCount(-1, data.length)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- data.codePointCount(0, data.length + 1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ data.codePointCount(0, data.length + 1)) | |
} | |
- test("compareTo") { | |
- assert("test".compareTo("utest") < 0) | |
- assert("test".compareTo("test") == 0) | |
- assert("test".compareTo("stest") > 0) | |
- assert("test".compareTo("tess") > 0) | |
+ @Test def compareTo(): Unit = { | |
+ assertTrue("test".compareTo("utest") < 0) | |
+ assertTrue("test".compareTo("test") == 0) | |
+ assertTrue("test".compareTo("stest") > 0) | |
+ assertTrue("test".compareTo("tess") > 0) | |
} | |
- test("compareToIgnoreCase") { | |
- assert("test".compareToIgnoreCase("Utest") < 0) | |
- assert("test".compareToIgnoreCase("Test") == 0) | |
- assert("Test".compareToIgnoreCase("stest") > 0) | |
- assert("tesT".compareToIgnoreCase("teSs") > 0) | |
+ @Test def compareToIgnoreCase(): Unit = { | |
+ assertTrue("test".compareToIgnoreCase("Utest") < 0) | |
+ assertTrue("test".compareToIgnoreCase("Test") == 0) | |
+ assertTrue("Test".compareToIgnoreCase("stest") > 0) | |
+ assertTrue("tesT".compareToIgnoreCase("teSs") > 0) | |
} | |
- test("equalsIgnoreCase") { | |
- assert("test".equalsIgnoreCase("TEST")) | |
- assert("TEst".equalsIgnoreCase("teST")) | |
- assert(!("SEst".equalsIgnoreCase("TEss"))) | |
+ @Test def equalsIgnoreCase(): Unit = { | |
+ assertTrue("test".equalsIgnoreCase("TEST")) | |
+ assertTrue("TEst".equalsIgnoreCase("teST")) | |
+ assertTrue(!("SEst".equalsIgnoreCase("TEss"))) | |
} | |
- test("regionMatches") { | |
- assert("This is a test".regionMatches(10, "test", 0, 4)) | |
- assert(!("This is a test".regionMatches(10, "TEST", 0, 4))) | |
- assert("This is a test".regionMatches(0, "This", 0, 4)) | |
+ @Test def regionMatches(): Unit = { | |
+ assertTrue("This is a test".regionMatches(10, "test", 0, 4)) | |
+ assertTrue(!("This is a test".regionMatches(10, "TEST", 0, 4))) | |
+ assertTrue("This is a test".regionMatches(0, "This", 0, 4)) | |
} | |
- test("replace Char") { | |
- assert("test".replace('t', 'p') equals "pesp") | |
- assert("Test".replace('t', 'p') equals "Tesp") | |
- assert("Test".replace('T', 'p') equals "pest") | |
- assert("Test".replace('0', '1') equals "Test") | |
+ @Test def replaceChar(): Unit = { | |
+ assertTrue("test".replace('t', 'p') equals "pesp") | |
+ assertTrue("Test".replace('t', 'p') equals "Tesp") | |
+ assertTrue("Test".replace('T', 'p') equals "pest") | |
+ assertTrue("Test".replace('0', '1') equals "Test") | |
} | |
- test("replace CharSequence") { | |
+ @Test def replaceCharSequence(): Unit = { | |
// Runs assertion with and without prefix and suffix | |
def check(input: String, replace: String => Boolean) = { | |
- assert(replace(input)) | |
+ assertTrue(replace(input)) | |
val inputWithPrefix = ("[" + input).substring(1) | |
- assert(inputWithPrefix equals input) | |
- assert(replace(inputWithPrefix)) | |
+ assertTrue(inputWithPrefix equals input) | |
+ assertTrue(replace(inputWithPrefix)) | |
val inputWithSuffix = (input + "]").substring(0, input.length) | |
- assert(inputWithSuffix equals input) | |
- assert(replace(inputWithSuffix)) | |
+ assertTrue(inputWithSuffix equals input) | |
+ assertTrue(replace(inputWithSuffix)) | |
val inputWithBoth = ("[" + input + "]").substring(1, input.length + 1) | |
- assert(inputWithBoth equals input) | |
- assert(replace(inputWithBoth)) | |
+ assertTrue(inputWithBoth equals input) | |
+ assertTrue(replace(inputWithBoth)) | |
} | |
check("test", _.replace("t", "p") equals "pesp") | |
@@ -167,19 +168,20 @@ object StringSuite extends tests.Suite { | |
check("Test", _.replace("", "--") equals "--T--e--s--t--") | |
} | |
- test("replaceAll non-ascii") { | |
+ @Test def replaceAllNonAscii(): Unit = { | |
val greetings = "Gruesze" | |
val greetingsWithUmlaut = greetings.replaceAll("ue", "ü") | |
- assert(greetingsWithUmlaut == "Grüsze") | |
+ assertTrue(greetingsWithUmlaut == "Grüsze") | |
val greetingsWithUmlautAndSharpS = greetingsWithUmlaut.replaceAll("sz", "ß") | |
- assert(greetingsWithUmlautAndSharpS == "Grüße") | |
+ assertTrue(greetingsWithUmlautAndSharpS == "Grüße") | |
- assert("Grueszszszeszszszszsze".replaceAll("sz", "ß") == "Grueßßßeßßßßße") | |
+ assertTrue( | |
+ "Grueszszszeszszszszsze".replaceAll("sz", "ß") == "Grueßßßeßßßßße") | |
} | |
- test("replaceAllLiterally with $ in replacement, issue #1070") { | |
+ @Test def replaceAllLiterallyWithDollarSignInReplacementIssue1070(): Unit = { | |
val literal = "{.0}" | |
val replacement = "\\$ipsum" | |
val prefix = "Lorem " | |
@@ -187,80 +189,82 @@ object StringSuite extends tests.Suite { | |
val text = prefix + literal + suffix | |
val expected = prefix + replacement + suffix | |
- assert(text.replaceAllLiterally(literal, replacement) == expected) | |
+ assertTrue(text.replaceAllLiterally(literal, replacement) == expected) | |
} | |
- private implicit class StringOps(val s: String) extends AnyVal { | |
- def splitVec(sep: String, limit: Int = 0) = s.split(sep, limit).toVector | |
- } | |
+ private def splitVec(s: String, sep: String, limit: Int = 0) = | |
+ s.split(sep, limit).toVector | |
+ | |
private def splitTest(sep: String, splitExpr: Option[String] = None) = { | |
val splitSep = splitExpr getOrElse sep | |
val n = 4 | |
val limit = 2 | |
- assert("".splitVec(splitSep) == Vector("")) | |
- assert("".splitVec(splitSep, limit) == Vector("")) | |
+ assertTrue(splitVec("", splitSep) == Vector("")) | |
+ assertTrue(splitVec("", splitSep, limit) == Vector("")) | |
val noSep = "b" | |
- assert(noSep.splitVec(splitSep) == Vector(noSep)) | |
- assert(noSep.splitVec(splitSep, limit) == Vector(noSep)) | |
+ assertTrue(splitVec(noSep, splitSep) == Vector(noSep)) | |
+ assertTrue(splitVec(noSep, splitSep, limit) == Vector(noSep)) | |
(1 to n) foreach { i => | |
val allSep = sep * n | |
- assert(allSep.splitVec(splitSep) == Vector.empty) | |
- assert( | |
- allSep.splitVec(splitSep, n) == (0 until (n - 1)) | |
+ assertTrue(splitVec(allSep, splitSep) == Vector.empty) | |
+ assertTrue( | |
+ splitVec(allSep, splitSep, n) == (0 until (n - 1)) | |
.map(_ => "") | |
.toVector :+ sep) | |
- assert( | |
- allSep.splitVec(splitSep, limit) == (0 until (limit - 1)) | |
+ assertTrue( | |
+ splitVec(allSep, splitSep, limit) == (0 until (limit - 1)) | |
.map(_ => "") | |
.toVector :+ allSep.drop((limit - 1) * sep.length)) | |
} | |
val oneSep = noSep + sep | |
- assert(oneSep.splitVec(splitSep) == Vector(noSep)) | |
- assert(oneSep.splitVec(splitSep, 1) == Vector(oneSep)) | |
- assert(oneSep.splitVec(splitSep, 2) == Vector(noSep, "")) | |
+ assertTrue(splitVec(oneSep, splitSep) == Vector(noSep)) | |
+ assertTrue(splitVec(oneSep, splitSep, 1) == Vector(oneSep)) | |
+ assertTrue(splitVec(oneSep, splitSep, 2) == Vector(noSep, "")) | |
val twoSep = oneSep * 2 | |
- assert(twoSep.splitVec(splitSep) == Vector(noSep, noSep)) | |
- assert(twoSep.splitVec(splitSep, 1) == Vector(twoSep)) | |
- assert(twoSep.splitVec(splitSep, 2) == Vector(noSep, oneSep)) | |
- assert(twoSep.splitVec(splitSep, 3) == Vector(noSep, noSep, "")) | |
+ assertTrue(splitVec(twoSep, splitSep) == Vector(noSep, noSep)) | |
+ assertTrue(splitVec(twoSep, splitSep, 1) == Vector(twoSep)) | |
+ assertTrue(splitVec(twoSep, splitSep, 2) == Vector(noSep, oneSep)) | |
+ assertTrue(splitVec(twoSep, splitSep, 3) == Vector(noSep, noSep, "")) | |
val leadingSep = sep + noSep | |
- assert(leadingSep.splitVec(splitSep) == Vector("", noSep)) | |
- assert(leadingSep.splitVec(splitSep, 1) == Vector(leadingSep)) | |
- assert(leadingSep.splitVec(splitSep, 2) == Vector("", noSep)) | |
- assert(leadingSep.splitVec(splitSep, 3) == Vector("", noSep)) | |
+ assertTrue(splitVec(leadingSep, splitSep) == Vector("", noSep)) | |
+ assertTrue(splitVec(leadingSep, splitSep, 1) == Vector(leadingSep)) | |
+ assertTrue(splitVec(leadingSep, splitSep, 2) == Vector("", noSep)) | |
+ assertTrue(splitVec(leadingSep, splitSep, 3) == Vector("", noSep)) | |
val trailingSep = noSep + sep | |
- assert(trailingSep.splitVec(splitSep) == Vector(noSep)) | |
- assert(trailingSep.splitVec(splitSep, 1) == Vector(trailingSep)) | |
- assert(trailingSep.splitVec(splitSep, 2) == Vector(noSep, "")) | |
- assert(trailingSep.splitVec(splitSep, 3) == Vector(noSep, "")) | |
+ assertTrue(splitVec(trailingSep, splitSep) == Vector(noSep)) | |
+ assertTrue(splitVec(trailingSep, splitSep, 1) == Vector(trailingSep)) | |
+ assertTrue(splitVec(trailingSep, splitSep, 2) == Vector(noSep, "")) | |
+ assertTrue(splitVec(trailingSep, splitSep, 3) == Vector(noSep, "")) | |
val leadingPlusTrailing = sep + noSep + sep | |
- assert(leadingPlusTrailing.splitVec(splitSep) == Vector("", noSep)) | |
- assert( | |
- leadingPlusTrailing.splitVec(splitSep, 1) == Vector(leadingPlusTrailing)) | |
- assert(leadingPlusTrailing.splitVec(splitSep, 2) == Vector("", oneSep)) | |
- assert(leadingPlusTrailing.splitVec(splitSep, 3) == Vector("", noSep, "")) | |
- assert(leadingPlusTrailing.splitVec(splitSep, 4) == Vector("", noSep, "")) | |
- } | |
- test("split") { | |
+ assertTrue(splitVec(leadingPlusTrailing, splitSep) == Vector("", noSep)) | |
+ assertTrue( | |
+ splitVec(leadingPlusTrailing, splitSep, 1) == Vector(leadingPlusTrailing)) | |
+ assertTrue(splitVec(leadingPlusTrailing, splitSep, 2) == Vector("", oneSep)) | |
+ assertTrue( | |
+ splitVec(leadingPlusTrailing, splitSep, 3) == Vector("", noSep, "")) | |
+ assertTrue( | |
+ splitVec(leadingPlusTrailing, splitSep, 4) == Vector("", noSep, "")) | |
+ } | |
+ @Test def split(): Unit = { | |
splitTest("a") | |
splitTest(".", splitExpr = Some("\\.")) | |
splitTest("ab", splitExpr = Some("ab")) | |
splitTest("ab", splitExpr = Some("(ab)")) | |
} | |
- test("getBytes") { | |
+ @Test def getBytes(): Unit = { | |
val b = new Array[scala.Byte](4) | |
// This form of getBytes() has been depricated since JDK 1.1 | |
"This is a test".getBytes(10, 14, b, 0) | |
- assert(new String(b) equals "test") | |
+ assertTrue(new String(b) equals "test") | |
} | |
def testEncoding(charset: String, expectedInts: Seq[Int]): Unit = { | |
@@ -284,30 +288,28 @@ object StringSuite extends tests.Suite { | |
val bytes = text.getBytes(charset) | |
val expectedBytes = expectedInts.map(i => java.lang.Byte.valueOf(i.toByte)) | |
val expected = Array[java.lang.Byte](expectedBytes: _*) | |
- assert(bytes.sameElements(expected), "result != expected}") | |
+ assertTrue("result != expected}", bytes.sameElements(expected)) | |
} | |
- test("getBytes(\"UTF-8\")") { | |
-// format: off | |
+ @Test def getBytesUTF8(): Unit = { | |
+ | |
val expectedInts = | |
- Seq(0, 9, 10, 65, 90, 97, 122, 48, 57, 64, 126, // one byte unicode | |
- -61, -97, // two byte unicode | |
- -28, -71, -90, // three byte unicode | |
- -31, -67, -112, 65 // four byte unicode | |
- ) | |
-// format: on | |
+ Seq(0, 9, 10, 65, 90, 97, 122, 48, 57, 64, 126, // one byte unicode | |
+ -61, -97, // two byte unicode | |
+ -28, -71, -90, // three byte unicode | |
+ -31, -67, -112, 65 // four byte unicode | |
+ ) | |
+ | |
testEncoding(StandardCharsets.UTF_8, expectedInts) | |
testEncoding("UTF-8", expectedInts) | |
} | |
- test("getBytes(\"UTF-16\"") { | |
- // format: off | |
- val expectedBE = Seq( | |
- 0, 0, 0, 9, 0, 10, 0, 65, 0, 90, | |
- 0, 97, 0, 122, 0, 48, 0, 57, 0, 64, | |
- 0, 126, 0, -33, 78, 102, 31, 80, 0, 65 | |
- ) | |
- // format: on | |
+ @Test def getBytesUTF16(): Unit = { | |
+ val expectedBE = | |
+ Seq( | |
+ 0, 0, 0, 9, 0, 10, 0, 65, 0, 90, 0, 97, 0, 122, 0, 48, 0, 57, 0, 64, 0, | |
+ 126, 0, -33, 78, 102, 31, 80, 0, 65 | |
+ ) | |
val expectedLE = expectedBE | |
.sliding(2, 2) | |
@@ -324,99 +326,99 @@ object StringSuite extends tests.Suite { | |
testEncoding("UTF-16", expectedWithBOM) | |
} | |
- test("getBytes unsupported encoding") { | |
- assertThrows[java.io.UnsupportedEncodingException] { | |
- "This is a test".getBytes("unsupported encoding") | |
- } | |
+ @Test def getBytesUnsupportedEncoding(): Unit = { | |
+ assertThrows(classOf[java.io.UnsupportedEncodingException], | |
+ "This is a test".getBytes("unsupported encoding")) | |
} | |
- test("literals have consistent hash code implementation") { | |
- assert( | |
- "foobar".hashCode == new String(Array('f', 'o', 'o', 'b', 'a', 'r')).hashCode) | |
+ @Test def literalsHaveConsistentHashCodeImplementation(): Unit = { | |
+ assertTrue("foobar".hashCode == new String( | |
+ Array('f', 'o', 'o', 'b', 'a', 'r')).hashCode) | |
} | |
- testFails("intern", issue = 486) { | |
+ @Ignore("#486") | |
+ @Test def intern(): Unit = { | |
val chars = Array('f', 'o', 'o', 'b', 'a', 'r') | |
val s1 = new String(chars) | |
val s2 = new String(chars) | |
- assert(s1.intern eq s2.intern) | |
- } | |
- | |
- test("indexOf") { | |
- assert("afoobar".indexOf("a") == 0) | |
- assert("afoobar".indexOf(97) == 0) | |
- assert("afoobar".indexOf("a", 1) == 5) | |
- assert("afoobar".indexOf(97, 1) == 5) | |
- assert("".indexOf("a") == -1) | |
- assert("".indexOf(97) == -1) | |
- assert("".indexOf("a", 4) == -1) | |
- assert("".indexOf(97, 4) == -1) | |
- assert("fubår".indexOf("a") == -1) | |
- assert("fubår".indexOf(97) == -1) | |
- assert("fubår".indexOf("a", 4) == -1) | |
- assert("fubår".indexOf(97, 4) == -1) | |
- } | |
- | |
- test("lastIndexOf") { | |
- assert("afoobar".lastIndexOf("a") == 5) | |
- assert("afoobar".lastIndexOf(97) == 5) | |
- assert("afoobar".lastIndexOf("a", 4) == 0) | |
- assert("afoobar".lastIndexOf(97, 4) == 0) | |
- assert("".lastIndexOf("a") == -1) | |
- assert("".lastIndexOf(97) == -1) | |
- assert("".lastIndexOf("a", 4) == -1) | |
- assert("".lastIndexOf(97, 4) == -1) | |
- assert("fubår".lastIndexOf("a") == -1) | |
- assert("fubår".lastIndexOf(97) == -1) | |
- assert("fubår".lastIndexOf("a", 4) == -1) | |
- assert("fubår".lastIndexOf(97, 4) == -1) | |
- } | |
- | |
- test("toUpperCase") { | |
- assert("".toUpperCase() equals "") | |
+ assertTrue(s1.intern eq s2.intern) | |
+ } | |
+ | |
+ @Test def indexOf(): Unit = { | |
+ assertTrue("afoobar".indexOf("a") == 0) | |
+ assertTrue("afoobar".indexOf(97) == 0) | |
+ assertTrue("afoobar".indexOf("a", 1) == 5) | |
+ assertTrue("afoobar".indexOf(97, 1) == 5) | |
+ assertTrue("".indexOf("a") == -1) | |
+ assertTrue("".indexOf(97) == -1) | |
+ assertTrue("".indexOf("a", 4) == -1) | |
+ assertTrue("".indexOf(97, 4) == -1) | |
+ assertTrue("fubår".indexOf("a") == -1) | |
+ assertTrue("fubår".indexOf(97) == -1) | |
+ assertTrue("fubår".indexOf("a", 4) == -1) | |
+ assertTrue("fubår".indexOf(97, 4) == -1) | |
+ } | |
+ | |
+ @Test def lastIndexOf(): Unit = { | |
+ assertTrue("afoobar".lastIndexOf("a") == 5) | |
+ assertTrue("afoobar".lastIndexOf(97) == 5) | |
+ assertTrue("afoobar".lastIndexOf("a", 4) == 0) | |
+ assertTrue("afoobar".lastIndexOf(97, 4) == 0) | |
+ assertTrue("".lastIndexOf("a") == -1) | |
+ assertTrue("".lastIndexOf(97) == -1) | |
+ assertTrue("".lastIndexOf("a", 4) == -1) | |
+ assertTrue("".lastIndexOf(97, 4) == -1) | |
+ assertTrue("fubår".lastIndexOf("a") == -1) | |
+ assertTrue("fubår".lastIndexOf(97) == -1) | |
+ assertTrue("fubår".lastIndexOf("a", 4) == -1) | |
+ assertTrue("fubår".lastIndexOf(97, 4) == -1) | |
+ } | |
+ | |
+ @Test def toUpperCase(): Unit = { | |
+ assertTrue("".toUpperCase() equals "") | |
// ascii | |
- assert("Hello".toUpperCase() equals "HELLO") | |
+ assertTrue("Hello".toUpperCase() equals "HELLO") | |
// latin | |
- assert("Perché".toUpperCase() equals "PERCHÉ") | |
+ assertTrue("Perché".toUpperCase() equals "PERCHÉ") | |
// high (2 Char String) - 0x10400 or \ud801\udc00 | |
val iStr = new String(Character.toChars(0x10400)) | |
- assert(iStr.length equals 2) | |
- assert(iStr.toUpperCase equals iStr) | |
+ assertTrue(iStr.length equals 2) | |
+ assertTrue(iStr.toUpperCase equals iStr) | |
val bStr = "\ud801\udc00" | |
- assert(bStr.length equals 2) | |
- assert(bStr.toUpperCase equals "\ud801\udc00") | |
- assert("𐐨aaaa".toUpperCase equals "𐐀AAAA") | |
- assert("aaaa𐐨".toUpperCase equals "AAAA𐐀") | |
- assert("aa𐐨aa".toUpperCase equals "AA𐐀AA") | |
+ assertTrue(bStr.length equals 2) | |
+ assertTrue(bStr.toUpperCase equals "\ud801\udc00") | |
+ assertTrue("𐐨aaaa".toUpperCase equals "𐐀AAAA") | |
+ assertTrue("aaaa𐐨".toUpperCase equals "AAAA𐐀") | |
+ assertTrue("aa𐐨aa".toUpperCase equals "AA𐐀AA") | |
// partial in surrogate range | |
// case of poor slicing or construction of string | |
- assert("\ud801aaaa".toUpperCase equals "\ud801AAAA") | |
- assert("aaaa\ud801".toUpperCase equals "AAAA\ud801") | |
- assert("\udc00aaaa".toUpperCase equals "\udc00AAAA") | |
- assert("aaaa\udc00".toUpperCase equals "AAAA\udc00") | |
+ assertTrue("\ud801aaaa".toUpperCase equals "\ud801AAAA") | |
+ assertTrue("aaaa\ud801".toUpperCase equals "AAAA\ud801") | |
+ assertTrue("\udc00aaaa".toUpperCase equals "\udc00AAAA") | |
+ assertTrue("aaaa\udc00".toUpperCase equals "AAAA\udc00") | |
// case of one high surrogate | |
val hChar = '\ud801' | |
val hStr = hChar.toString | |
- assert(Character.isHighSurrogate(hChar) equals true) | |
- assert(hStr.length equals 1) | |
- assert(hStr.toUpperCase equals hStr) | |
+ assertTrue(Character.isHighSurrogate(hChar) equals true) | |
+ assertTrue(hStr.length equals 1) | |
+ assertTrue(hStr.toUpperCase equals hStr) | |
// toUpperCase should consider String's offset | |
- assert( | |
+ assertTrue( | |
"Hi, Scala Native!" | |
.subSequence(4, 16) | |
.toString | |
.toUpperCase equals "SCALA NATIVE") | |
} | |
- test("toLowerCase") { | |
- assert("".toLowerCase() equals "") | |
- assert("Hello".toLowerCase() equals "hello") | |
- assert("PERCHÉ".toLowerCase() equals "perché") | |
- assert("𐐀AAAA".toLowerCase equals "𐐨aaaa") | |
- assert("AAAA𐐀".toLowerCase equals "aaaa𐐨") | |
- assert("AA𐐀AA".toLowerCase equals "aa𐐨aa") | |
+ @Test def toLowerCase(): Unit = { | |
+ assertTrue("".toLowerCase() equals "") | |
+ assertTrue("Hello".toLowerCase() equals "hello") | |
+ assertTrue("PERCHÉ".toLowerCase() equals "perché") | |
+ assertTrue("𐐀AAAA".toLowerCase equals "𐐨aaaa") | |
+ assertTrue("AAAA𐐀".toLowerCase equals "aaaa𐐨") | |
+ assertTrue("AA𐐀AA".toLowerCase equals "aa𐐨aa") | |
// toLowerCase should consider String's offset | |
- assert( | |
+ assertTrue( | |
"Hi, Scala Native!" | |
.subSequence(4, 16) | |
.toString | |
diff --git a/unit-tests/src/test/scala/java/lang/CharacterSuite.scala b/unit-tests/src/test/scala/java/lang/CharacterTest.scala | |
index c3955405..a5ce1d6e 100644 | |
--- a/unit-tests/src/test/scala/java/lang/CharacterSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/CharacterTest.scala | |
@@ -10,60 +10,60 @@ package java.lang | |
* Surrogate code points are in the gap and U+FFFF | |
* is the max value for [[scala.Char]]. | |
*/ | |
-object CharacterSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class CharacterTest { | |
import java.lang.Character._ | |
// codePointAt tests | |
- test("codePointAt - invalid values") { | |
+ @Test def codePointAtInvalidValues(): Unit = { | |
val str1 = "<invalid values>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 2) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 2)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[CharSequence], 2) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[CharSequence], 2)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(arr1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(arr1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(str1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(str1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(arr1, 2, arr1.length + 1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(arr1, 2, arr1.length + 1)) | |
} | |
- test("codePointAt - Array[Char]") { | |
+ @Test def codePointAtArrayChar(): Unit = { | |
val arr1 = "abcdEfghIjklMnoPqrsTuvwXyz".toArray | |
val result = Character.codePointAt(arr1, 3, arr1.length) | |
val expected = 100 // 'd' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointAt - CharSeq") { | |
+ @Test def codePointAtCharSeq(): Unit = { | |
val charSeq1: CharSequence = "abcdEfghIjklMnoPqrsTuvwXyz" | |
val result = Character.codePointAt(charSeq1, 8) | |
val expected = 73 // 'I' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointAt - Array[Char],CharSeq return same non-ASCII value") { | |
+ @Test def codePointAtArrayCharCharSeqReturnSameNonAsciiValue(): Unit = { | |
val str1 = "30\u20ac" // 'euro-character' | |
val index = str1.length - 1 | |
@@ -71,22 +71,26 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0x20AC // 'euro-character' | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - low surrogate at beginning of line") { | |
+ @Test def codePointAtLowSurrogateAtBeginningOfLine(): Unit = { | |
val str1 = "\uDC00eol" // Character.MIN_LOW_SURROGATE | |
val index = 0 | |
val resultCA = Character.codePointAt(str1.toArray, index, str1.length) | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDC00 // Character.MIN_LOW_SURROGATE, 56320 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - high surrogate at end of line") { | |
+ @Test def codePointAtHighSurrogateAtEndOfLine(): Unit = { | |
val str1 = "eol\uDBFF" // Character.MAX_HIGH_SURROGATE | |
val index = str1.length - 1 | |
@@ -94,11 +98,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDBFF // Character.MAX_HIGH_SURROGATE, 56319 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - surrogate pair") { | |
+ @Test def codePointAtSurrogatePair(): Unit = { | |
// Character.MIN_HIGH_SURROGATE followed by Character.MAX_LOW_SURROGATE | |
val str1 = "before \uD800\uDFFF after" | |
val index = 7 | |
@@ -107,11 +113,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0x103FF // surrogate pair, decimal 66559 | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - high-non-high surrogate") { | |
+ @Test def codePointAtHighNonHighSurrogate(): Unit = { | |
val str1 = "a\uDBFFb\uDBFFc" | |
val indexes = Seq(1, 3) | |
indexes.foreach { index => | |
@@ -119,14 +127,14 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDBFF | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointAt - low-non-low surrogate") { | |
+ @Test def codePointAtLowNonLowSurrogate(): Unit = { | |
val str1 = "a\uDC00b\uDC00c" | |
val indexes = Seq(1, 3) | |
indexes.foreach { index => | |
@@ -134,66 +142,60 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDC00 | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
// codePointBefore tests | |
- test("codePointBefore - invalid values") { | |
+ @Test def codePointBeforeInvalidValues(): Unit = { | |
val str1 = "<invalid values>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointBefore(null.asInstanceOf[Array[Char]], 1) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointBefore(null.asInstanceOf[Array[Char]], 1)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointBefore(null.asInstanceOf[CharSequence], 1) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointBefore(null.asInstanceOf[CharSequence], 1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(arr1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(arr1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(str1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(str1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(arr1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(arr1, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(str1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(str1, 0)) | |
} | |
- test("codePointBefore - Array[Char]") { | |
+ @Test def codePointBeforeArrayChar(): Unit = { | |
val arr1 = "abcdEfghIjklMnopQrstUvwxYz".toArray | |
val index = 10 | |
val result = Character.codePointBefore(arr1, index) | |
val expected = 106 // 'j' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointBefore - CharSeq") { | |
+ @Test def codePointBeforeCharSeq(): Unit = { | |
val str1 = "abcdEfghIjklMnoPqrsTuvwXyz" | |
val index = str1.length - 1 | |
val result = Character.codePointBefore(str1, index) | |
val expected = 121 // 'y' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointBefore - Array[Char], CharSeq return same non-ASCII value") { | |
+ @Test def codePointBeforeArrayCharCharSeqReturnSamNonAsciiValue(): Unit = { | |
val str1 = "bugsabound\u03bb" // Greek small letter lambda | |
val index = str1.length | |
@@ -201,22 +203,26 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 955 // Greek snall letter lambda | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - low surrogate at beginning of line") { | |
+ @Test def codePointBeforeLowSurrogateAtBeginningOfLine(): Unit = { | |
val str1 = "\uDC00eol" // Character.MIN_LOW_SURROGATE | |
val index = 1 | |
val resultCA = Character.codePointBefore(str1.toArray, index) | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDC00 // Character.MIN_LOW_SURROGATE, 56320 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - high surrogate at end of line") { | |
+ @Test def codePointBeforeHighSurrogateAtEndOfLine(): Unit = { | |
val str1 = "eol\uDBFF" // Character.MAX_HIGH_SURROGATE | |
val index = str1.length | |
@@ -224,11 +230,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDBFF // Character.MAX_HIGH_SURROGATE, 56319 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - surrogate pair") { | |
+ @Test def codePointBeforeSurrogatePair(): Unit = { | |
// Character.MIN_HIGH_SURROGATE followed by Character.MAX_LOW_SURROGATE | |
val str1 = "Denali\uD800\uDFFF" | |
val index = str1.length | |
@@ -237,11 +245,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0x103FF // surrogate pair, decimal 66559 | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - high-non-high surrogate") { | |
+ @Test def codePointBeforeHighNonHighSurrogate(): Unit = { | |
val str1 = "a\uDBFFb\uDBFFc" | |
val indexes = Seq(2, 4) | |
indexes.foreach { index => | |
@@ -249,14 +259,14 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDBFF | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointBefore - low-non-low surrogate") { | |
+ @Test def codePointBeforeLowNonLowSurrogate(): Unit = { | |
val str1 = "a\uDC00b\uDC00c" | |
val indexes = Seq(2, 4) | |
indexes.foreach { index => | |
@@ -264,20 +274,20 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDC00 | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointCount") { | |
+ @Test def codePointCount(): Unit = { | |
val data = "Mt. Whitney".toArray[scala.Char] | |
val offset = 1 | |
val expected = data.size - offset | |
val result = Character.codePointCount(data, offset, expected) | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
// Ported, with gratitude & possibly modifications | |
@@ -286,12 +296,9 @@ object CharacterSuite extends tests.Suite { | |
// test-suite/shared/src/test/scala/org/scalajs/testsuite/ | |
// javalib/lang/CharacterTest.scala | |
- test("digit") { | |
- | |
- // method test() in ScalaJS, but that name already in use in test Suite. | |
- // To assay is, roughly "to judge the worth of" or "try, attempt". | |
+ @Test def digit(): Unit = { | |
- def assay(expected: Int, codePoint: Int): Unit = { | |
+ def test(expected: Int, codePoint: Int): Unit = { | |
assertEquals(expected, Character.digit(codePoint, MAX_RADIX)) | |
if (codePoint <= Char.MaxValue) | |
assertEquals(expected, Character.digit(codePoint.toChar, MAX_RADIX)) | |
@@ -317,42 +324,41 @@ object CharacterSuite extends tests.Suite { | |
assertEquals(-1, Character.digit('0'.toInt, -1)) | |
// A few invalid digits | |
- assay(-1, '}') | |
- assay(-1, -4) | |
- assay(-1, 0xffffff) | |
- assay(-1, '0' - 1) | |
- assay(-1, '9' + 1) | |
- assay(-1, 'A' - 1) | |
- assay(-1, 'Z' + 1) | |
- assay(-1, 'a' - 1) | |
- assay(-1, 'z' + 1) | |
- assay(-1, 0xff20) | |
- assay(-1, 0xff3b) | |
- assay(-1, 0xff40) | |
- assay(-1, 0xff5b) | |
- assay(-1, 0xbe5) | |
- assay(-1, 0xbf0) | |
- assay(-1, 0x11065) | |
- assay(-1, 0x11070) | |
- assay(-1, Int.MinValue) | |
- assay(-1, Int.MaxValue) | |
+ test(-1, '}') | |
+ test(-1, -4) | |
+ test(-1, 0xffffff) | |
+ test(-1, '0' - 1) | |
+ test(-1, '9' + 1) | |
+ test(-1, 'A' - 1) | |
+ test(-1, 'Z' + 1) | |
+ test(-1, 'a' - 1) | |
+ test(-1, 'z' + 1) | |
+ test(-1, 0xff20) | |
+ test(-1, 0xff3b) | |
+ test(-1, 0xff40) | |
+ test(-1, 0xff5b) | |
+ test(-1, 0xbe5) | |
+ test(-1, 0xbf0) | |
+ test(-1, 0x11065) | |
+ test(-1, 0x11070) | |
+ test(-1, Int.MinValue) | |
+ test(-1, Int.MaxValue) | |
// Every single valid digit | |
-// format: off | |
- val All0s = Array[Int]('0', 0x660, 0x6f0, 0x7c0, 0x966, 0x9e6, 0xa66, | |
- 0xae6, 0xb66, 0xbe6, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, | |
- 0x1090, 0x17e0, 0x1810, 0x1946, 0x19d0, 0x1a80, 0x1a90, 0x1b50, 0x1bb0, | |
- 0x1c40, 0x1c50, 0xa620, 0xa8d0, 0xa900, 0xa9d0, 0xaa50, 0xabf0, 0xff10, | |
- 0x104a0, 0x11066, 0x110f0, 0x11136, 0x111d0, 0x116c0, 0x1d7ce, 0x1d7d8, | |
- 0x1d7e2, 0x1d7ec, 0x1d7f6) | |
-// format: on | |
+ val All0s = | |
+ Array[Int]('0', 0x660, 0x6f0, 0x7c0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, | |
+ 0xbe6, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x1090, 0x17e0, | |
+ 0x1810, 0x1946, 0x19d0, 0x1a80, 0x1a90, 0x1b50, 0x1bb0, 0x1c40, 0x1c50, | |
+ 0xa620, 0xa8d0, 0xa900, 0xa9d0, 0xaa50, 0xabf0, 0xff10, 0x104a0, | |
+ 0x11066, 0x110f0, 0x11136, 0x111d0, 0x116c0, 0x1d7ce, 0x1d7d8, 0x1d7e2, | |
+ 0x1d7ec, 0x1d7f6) | |
for { | |
zero <- All0s | |
offset <- 0 to 9 | |
} { | |
- assay(offset, zero + offset) | |
+ test(offset, zero + offset) | |
} | |
val AllAs = Array[Int]('A', 'a', 0xff21, 0xff41) | |
@@ -361,143 +367,138 @@ object CharacterSuite extends tests.Suite { | |
a <- AllAs | |
offset <- 0 to 25 | |
} { | |
- assay(10 + offset, a + offset) | |
+ test(10 + offset, a + offset) | |
} | |
} | |
- test("offsetByCodePoints - invalid values") { | |
+ @Test def offsetByCodePointsInvalidValues(): Unit = { | |
val str1 = "<bad args>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.offsetByCodePoints(null.asInstanceOf[Array[Char]], | |
- 1, | |
- arr1.length, | |
- 0, | |
- 0) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.offsetByCodePoints(null.asInstanceOf[Array[Char]], | |
+ 1, | |
+ arr1.length, | |
+ 0, | |
+ 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, -1, arr1.length, 0, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, -1, arr1.length, 0, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 0, -1, 0, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 0, -1, 0, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 1, arr1.length, 2, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 1, arr1.length, 2, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 2, arr1.length, 1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 2, arr1.length, 1, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 2, arr1.length, arr1.length + 1, 0) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 2, arr1.length, arr1.length + 1, 0)) | |
} | |
- test("toLowerCase-low") { | |
+ @Test def toLowerCaseLow(): Unit = { | |
// low chars | |
- assert(toLowerCase('\n') equals '\n') | |
+ assertTrue(toLowerCase('\n') equals '\n') | |
} | |
- test("toLowerCase-ascii") { | |
+ @Test def toLowerCaseAscii(): Unit = { | |
// ascii chars | |
- assert(toLowerCase('A') equals 'a') | |
- assert(toLowerCase('a') equals 'a') | |
- assertNot(toLowerCase('a') equals 'A') | |
- assert(toLowerCase('F') equals 'f') | |
- assert(toLowerCase('Z') equals 'z') | |
+ assertTrue(toLowerCase('A') equals 'a') | |
+ assertTrue(toLowerCase('a') equals 'a') | |
+ assertFalse(toLowerCase('a') equals 'A') | |
+ assertTrue(toLowerCase('F') equals 'f') | |
+ assertTrue(toLowerCase('Z') equals 'z') | |
} | |
- test("toLowerCase-compat") { | |
+ @Test def toLowerCaseCompat(): Unit = { | |
// compat characters are directly from the DB | |
// (03F4,GREEK CAPITAL THETA SYMBOL,Lu,0,L,<compat> 0398,N,,03B8,) | |
- assert(toLowerCase(0x03F4) equals 0x03B8) | |
- assert(toLowerCase('Θ') equals 'θ') | |
+ assertTrue(toLowerCase(0x03F4) equals 0x03B8) | |
+ assertTrue(toLowerCase('Θ') equals 'θ') | |
// (2161,ROMAN NUMERAL TWO,Nl,0,L,<compat> 0049 0049,N,,2171,) | |
- assert(toLowerCase(0x2161) equals 0x2171) | |
+ assertTrue(toLowerCase(0x2161) equals 0x2171) | |
// check lower to lower | |
- assert(toLowerCase('µ') equals 'µ') | |
+ assertTrue(toLowerCase('µ') equals 'µ') | |
} | |
- test("toLowerCase-alt") { | |
+ @Test def toLowerCaseAlt(): Unit = { | |
// alternating upper and lower case | |
// (256,257,-1,0)(302,303,-1,2) | |
- assert(toLowerCase(256) equals 257) | |
- assert(toLowerCase(257) equals 257) | |
- assert(toLowerCase(258) equals 259) | |
- assert(toLowerCase(302) equals 303) | |
+ assertTrue(toLowerCase(256) equals 257) | |
+ assertTrue(toLowerCase(257) equals 257) | |
+ assertTrue(toLowerCase(258) equals 259) | |
+ assertTrue(toLowerCase(302) equals 303) | |
} | |
- test("toLowerCase-high") { | |
+ @Test def toLowerCaseHigh(): Unit = { | |
// high points | |
- assert(toLowerCase(65313) equals 65345) | |
- assert(toLowerCase(65338) equals 65370) | |
- assert(toLowerCase(65339) equals 65339) | |
+ assertTrue(toLowerCase(65313) equals 65345) | |
+ assertTrue(toLowerCase(65338) equals 65370) | |
+ assertTrue(toLowerCase(65339) equals 65339) | |
} | |
- test("toLowerCase-above") { | |
+ @Test def toLowerCaseAbove(): Unit = { | |
// top and above range | |
- assert(toLowerCase(0x10FFFF) equals 0x10FFFF) | |
- assert(toLowerCase(0x110000) equals 0x110000) | |
+ assertTrue(toLowerCase(0x10FFFF) equals 0x10FFFF) | |
+ assertTrue(toLowerCase(0x110000) equals 0x110000) | |
} | |
- test("toUpperCase-low") { | |
+ @Test def toUpperCaseLow(): Unit = { | |
// low chars | |
- assert(toUpperCase('\n') equals '\n') | |
+ assertTrue(toUpperCase('\n') equals '\n') | |
} | |
- test("toUpperCase-ascii") { | |
+ @Test def toUpperCaseAscii(): Unit = { | |
// ascii chars | |
- assert(toUpperCase('a') equals 'A') | |
- assert(toUpperCase('A') equals 'A') | |
- assertNot(toUpperCase('A') equals 'a') | |
- assert(toUpperCase('f') equals 'F') | |
- assert(toUpperCase('z') equals 'Z') | |
+ assertTrue(toUpperCase('a') equals 'A') | |
+ assertTrue(toUpperCase('A') equals 'A') | |
+ assertFalse(toUpperCase('A') equals 'a') | |
+ assertTrue(toUpperCase('f') equals 'F') | |
+ assertTrue(toUpperCase('z') equals 'Z') | |
} | |
- test("toUpperCase-compat") { | |
+ @Test def toUpperCaseCompat(): Unit = { | |
// compat characters are directly from the DB | |
// (03D0,GREEK BETA SYMBOL,Ll,0,L,<compat> 03B2,N,0392,,0392) | |
- assert(toUpperCase(0x03D0) equals 0x0392) | |
- assert(toUpperCase('β') equals 'Β') | |
+ assertTrue(toUpperCase(0x03D0) equals 0x0392) | |
+ assertTrue(toUpperCase('β') equals 'Β') | |
// (00B5,MICRO SIGN,Ll,0,L,<compat> 03BC,N,039C,,039C) | |
- assert(toUpperCase(0x00B5) equals 0x039C) | |
- assert(toUpperCase('μ') equals 'Μ') | |
+ assertTrue(toUpperCase(0x00B5) equals 0x039C) | |
+ assertTrue(toUpperCase('μ') equals 'Μ') | |
} | |
- test("toUpperCase-alt") { | |
+ @Test def toUpperCaseAlt(): Unit = { | |
// alternating upper and lower case | |
// (257,256,1,0)(303,302,1,2) | |
- assert(toUpperCase(257) equals 256) | |
- assert(toUpperCase(258) equals 258) | |
- assert(toUpperCase(259) equals 258) | |
- assert(toUpperCase(303) equals 302) | |
+ assertTrue(toUpperCase(257) equals 256) | |
+ assertTrue(toUpperCase(258) equals 258) | |
+ assertTrue(toUpperCase(259) equals 258) | |
+ assertTrue(toUpperCase(303) equals 302) | |
} | |
- test("toUpperCase-high") { | |
+ @Test def toUpperCaseHigh(): Unit = { | |
// high points | |
// (65345,65313,32,0)(65370,65338,32,1) | |
// (66600,66560,40,0)(66639,66599,40,1) | |
// (71872,71840,32,0)(71903,71871,32,1) | |
- assert(toUpperCase(65345) equals 65313) | |
- assert(toUpperCase(65370) equals 65338) | |
- assert(toUpperCase(66600) equals 66560) | |
+ assertTrue(toUpperCase(65345) equals 65313) | |
+ assertTrue(toUpperCase(65370) equals 65338) | |
+ assertTrue(toUpperCase(66600) equals 66560) | |
} | |
- test("toUpperCase-above") { | |
+ @Test def toUpperCaseAbove(): Unit = { | |
// top and above range | |
- assert(toUpperCase(0x10FFFF) equals 0x10FFFF) | |
- assert(toUpperCase(0x110000) equals 0x110000) | |
+ assertTrue(toUpperCase(0x10FFFF) equals 0x10FFFF) | |
+ assertTrue(toUpperCase(0x110000) equals 0x110000) | |
} | |
- test("UnicodeBlock.of") { | |
- assert(UnicodeBlock.of('a') equals UnicodeBlock.BASIC_LATIN) | |
- assert(UnicodeBlock.of('א') equals UnicodeBlock.HEBREW) | |
+ @Test def unicodeBlockOf(): Unit = { | |
+ assertTrue(UnicodeBlock.of('a') equals UnicodeBlock.BASIC_LATIN) | |
+ assertTrue(UnicodeBlock.of('א') equals UnicodeBlock.HEBREW) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/CharacterSuite.scala b/unit-tests/src/test/scala/java/lang/CharacterTest.scala | |
index c3955405..a5ce1d6e 100644 | |
--- a/unit-tests/src/test/scala/java/lang/CharacterSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/CharacterTest.scala | |
@@ -10,60 +10,60 @@ package java.lang | |
* Surrogate code points are in the gap and U+FFFF | |
* is the max value for [[scala.Char]]. | |
*/ | |
-object CharacterSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class CharacterTest { | |
import java.lang.Character._ | |
// codePointAt tests | |
- test("codePointAt - invalid values") { | |
+ @Test def codePointAtInvalidValues(): Unit = { | |
val str1 = "<invalid values>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 1, arr1.length)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[Array[Char]], 2) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[Array[Char]], 2)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointAt(null.asInstanceOf[CharSequence], 2) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointAt(null.asInstanceOf[CharSequence], 2)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(arr1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(arr1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(str1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(str1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointAt(arr1, 2, arr1.length + 1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointAt(arr1, 2, arr1.length + 1)) | |
} | |
- test("codePointAt - Array[Char]") { | |
+ @Test def codePointAtArrayChar(): Unit = { | |
val arr1 = "abcdEfghIjklMnoPqrsTuvwXyz".toArray | |
val result = Character.codePointAt(arr1, 3, arr1.length) | |
val expected = 100 // 'd' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointAt - CharSeq") { | |
+ @Test def codePointAtCharSeq(): Unit = { | |
val charSeq1: CharSequence = "abcdEfghIjklMnoPqrsTuvwXyz" | |
val result = Character.codePointAt(charSeq1, 8) | |
val expected = 73 // 'I' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointAt - Array[Char],CharSeq return same non-ASCII value") { | |
+ @Test def codePointAtArrayCharCharSeqReturnSameNonAsciiValue(): Unit = { | |
val str1 = "30\u20ac" // 'euro-character' | |
val index = str1.length - 1 | |
@@ -71,22 +71,26 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0x20AC // 'euro-character' | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - low surrogate at beginning of line") { | |
+ @Test def codePointAtLowSurrogateAtBeginningOfLine(): Unit = { | |
val str1 = "\uDC00eol" // Character.MIN_LOW_SURROGATE | |
val index = 0 | |
val resultCA = Character.codePointAt(str1.toArray, index, str1.length) | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDC00 // Character.MIN_LOW_SURROGATE, 56320 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - high surrogate at end of line") { | |
+ @Test def codePointAtHighSurrogateAtEndOfLine(): Unit = { | |
val str1 = "eol\uDBFF" // Character.MAX_HIGH_SURROGATE | |
val index = str1.length - 1 | |
@@ -94,11 +98,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDBFF // Character.MAX_HIGH_SURROGATE, 56319 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - surrogate pair") { | |
+ @Test def codePointAtSurrogatePair(): Unit = { | |
// Character.MIN_HIGH_SURROGATE followed by Character.MAX_LOW_SURROGATE | |
val str1 = "before \uD800\uDFFF after" | |
val index = 7 | |
@@ -107,11 +113,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0x103FF // surrogate pair, decimal 66559 | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointAt - high-non-high surrogate") { | |
+ @Test def codePointAtHighNonHighSurrogate(): Unit = { | |
val str1 = "a\uDBFFb\uDBFFc" | |
val indexes = Seq(1, 3) | |
indexes.foreach { index => | |
@@ -119,14 +127,14 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDBFF | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointAt - low-non-low surrogate") { | |
+ @Test def codePointAtLowNonLowSurrogate(): Unit = { | |
val str1 = "a\uDC00b\uDC00c" | |
val indexes = Seq(1, 3) | |
indexes.foreach { index => | |
@@ -134,66 +142,60 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointAt(str1, index) | |
val expected = 0xDC00 | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
// codePointBefore tests | |
- test("codePointBefore - invalid values") { | |
+ @Test def codePointBeforeInvalidValues(): Unit = { | |
val str1 = "<invalid values>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointBefore(null.asInstanceOf[Array[Char]], 1) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointBefore(null.asInstanceOf[Array[Char]], 1)) | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.codePointBefore(null.asInstanceOf[CharSequence], 1) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.codePointBefore(null.asInstanceOf[CharSequence], 1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(arr1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(arr1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(str1, -1) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(str1, -1)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(arr1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(arr1, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.codePointBefore(str1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.codePointBefore(str1, 0)) | |
} | |
- test("codePointBefore - Array[Char]") { | |
+ @Test def codePointBeforeArrayChar(): Unit = { | |
val arr1 = "abcdEfghIjklMnopQrstUvwxYz".toArray | |
val index = 10 | |
val result = Character.codePointBefore(arr1, index) | |
val expected = 106 // 'j' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointBefore - CharSeq") { | |
+ @Test def codePointBeforeCharSeq(): Unit = { | |
val str1 = "abcdEfghIjklMnoPqrsTuvwXyz" | |
val index = str1.length - 1 | |
val result = Character.codePointBefore(str1, index) | |
val expected = 121 // 'y' | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
- test("codePointBefore - Array[Char], CharSeq return same non-ASCII value") { | |
+ @Test def codePointBeforeArrayCharCharSeqReturnSamNonAsciiValue(): Unit = { | |
val str1 = "bugsabound\u03bb" // Greek small letter lambda | |
val index = str1.length | |
@@ -201,22 +203,26 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 955 // Greek snall letter lambda | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - low surrogate at beginning of line") { | |
+ @Test def codePointBeforeLowSurrogateAtBeginningOfLine(): Unit = { | |
val str1 = "\uDC00eol" // Character.MIN_LOW_SURROGATE | |
val index = 1 | |
val resultCA = Character.codePointBefore(str1.toArray, index) | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDC00 // Character.MIN_LOW_SURROGATE, 56320 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - high surrogate at end of line") { | |
+ @Test def codePointBeforeHighSurrogateAtEndOfLine(): Unit = { | |
val str1 = "eol\uDBFF" // Character.MAX_HIGH_SURROGATE | |
val index = str1.length | |
@@ -224,11 +230,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDBFF // Character.MAX_HIGH_SURROGATE, 56319 decimal | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - surrogate pair") { | |
+ @Test def codePointBeforeSurrogatePair(): Unit = { | |
// Character.MIN_HIGH_SURROGATE followed by Character.MAX_LOW_SURROGATE | |
val str1 = "Denali\uD800\uDFFF" | |
val index = str1.length | |
@@ -237,11 +245,13 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0x103FF // surrogate pair, decimal 66559 | |
- assert(resultCA == resultCS, s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
- test("codePointBefore - high-non-high surrogate") { | |
+ @Test def codePointBeforeHighNonHighSurrogate(): Unit = { | |
val str1 = "a\uDBFFb\uDBFFc" | |
val indexes = Seq(2, 4) | |
indexes.foreach { index => | |
@@ -249,14 +259,14 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDBFF | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointBefore - low-non-low surrogate") { | |
+ @Test def codePointBeforeLowNonLowSurrogate(): Unit = { | |
val str1 = "a\uDC00b\uDC00c" | |
val indexes = Seq(2, 4) | |
indexes.foreach { index => | |
@@ -264,20 +274,20 @@ object CharacterSuite extends tests.Suite { | |
val resultCS = Character.codePointBefore(str1, index) | |
val expected = 0xDC00 | |
- assert(resultCA == resultCS, | |
- s"resultCA: $resultCA != resultCS: $resultCS") | |
- assert(resultCA == expected, | |
- s"resultCA: $resultCA != expected: $expected") | |
+ assertTrue(s"resultCA: $resultCA != resultCS: $resultCS", | |
+ resultCA == resultCS) | |
+ assertTrue(s"resultCA: $resultCA != expected: $expected", | |
+ resultCA == expected) | |
} | |
} | |
- test("codePointCount") { | |
+ @Test def codePointCount(): Unit = { | |
val data = "Mt. Whitney".toArray[scala.Char] | |
val offset = 1 | |
val expected = data.size - offset | |
val result = Character.codePointCount(data, offset, expected) | |
- assert(result == expected, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", result == expected) | |
} | |
// Ported, with gratitude & possibly modifications | |
@@ -286,12 +296,9 @@ object CharacterSuite extends tests.Suite { | |
// test-suite/shared/src/test/scala/org/scalajs/testsuite/ | |
// javalib/lang/CharacterTest.scala | |
- test("digit") { | |
- | |
- // method test() in ScalaJS, but that name already in use in test Suite. | |
- // To assay is, roughly "to judge the worth of" or "try, attempt". | |
+ @Test def digit(): Unit = { | |
- def assay(expected: Int, codePoint: Int): Unit = { | |
+ def test(expected: Int, codePoint: Int): Unit = { | |
assertEquals(expected, Character.digit(codePoint, MAX_RADIX)) | |
if (codePoint <= Char.MaxValue) | |
assertEquals(expected, Character.digit(codePoint.toChar, MAX_RADIX)) | |
@@ -317,42 +324,41 @@ object CharacterSuite extends tests.Suite { | |
assertEquals(-1, Character.digit('0'.toInt, -1)) | |
// A few invalid digits | |
- assay(-1, '}') | |
- assay(-1, -4) | |
- assay(-1, 0xffffff) | |
- assay(-1, '0' - 1) | |
- assay(-1, '9' + 1) | |
- assay(-1, 'A' - 1) | |
- assay(-1, 'Z' + 1) | |
- assay(-1, 'a' - 1) | |
- assay(-1, 'z' + 1) | |
- assay(-1, 0xff20) | |
- assay(-1, 0xff3b) | |
- assay(-1, 0xff40) | |
- assay(-1, 0xff5b) | |
- assay(-1, 0xbe5) | |
- assay(-1, 0xbf0) | |
- assay(-1, 0x11065) | |
- assay(-1, 0x11070) | |
- assay(-1, Int.MinValue) | |
- assay(-1, Int.MaxValue) | |
+ test(-1, '}') | |
+ test(-1, -4) | |
+ test(-1, 0xffffff) | |
+ test(-1, '0' - 1) | |
+ test(-1, '9' + 1) | |
+ test(-1, 'A' - 1) | |
+ test(-1, 'Z' + 1) | |
+ test(-1, 'a' - 1) | |
+ test(-1, 'z' + 1) | |
+ test(-1, 0xff20) | |
+ test(-1, 0xff3b) | |
+ test(-1, 0xff40) | |
+ test(-1, 0xff5b) | |
+ test(-1, 0xbe5) | |
+ test(-1, 0xbf0) | |
+ test(-1, 0x11065) | |
+ test(-1, 0x11070) | |
+ test(-1, Int.MinValue) | |
+ test(-1, Int.MaxValue) | |
// Every single valid digit | |
-// format: off | |
- val All0s = Array[Int]('0', 0x660, 0x6f0, 0x7c0, 0x966, 0x9e6, 0xa66, | |
- 0xae6, 0xb66, 0xbe6, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, | |
- 0x1090, 0x17e0, 0x1810, 0x1946, 0x19d0, 0x1a80, 0x1a90, 0x1b50, 0x1bb0, | |
- 0x1c40, 0x1c50, 0xa620, 0xa8d0, 0xa900, 0xa9d0, 0xaa50, 0xabf0, 0xff10, | |
- 0x104a0, 0x11066, 0x110f0, 0x11136, 0x111d0, 0x116c0, 0x1d7ce, 0x1d7d8, | |
- 0x1d7e2, 0x1d7ec, 0x1d7f6) | |
-// format: on | |
+ val All0s = | |
+ Array[Int]('0', 0x660, 0x6f0, 0x7c0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, | |
+ 0xbe6, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x1090, 0x17e0, | |
+ 0x1810, 0x1946, 0x19d0, 0x1a80, 0x1a90, 0x1b50, 0x1bb0, 0x1c40, 0x1c50, | |
+ 0xa620, 0xa8d0, 0xa900, 0xa9d0, 0xaa50, 0xabf0, 0xff10, 0x104a0, | |
+ 0x11066, 0x110f0, 0x11136, 0x111d0, 0x116c0, 0x1d7ce, 0x1d7d8, 0x1d7e2, | |
+ 0x1d7ec, 0x1d7f6) | |
for { | |
zero <- All0s | |
offset <- 0 to 9 | |
} { | |
- assay(offset, zero + offset) | |
+ test(offset, zero + offset) | |
} | |
val AllAs = Array[Int]('A', 'a', 0xff21, 0xff41) | |
@@ -361,143 +367,138 @@ object CharacterSuite extends tests.Suite { | |
a <- AllAs | |
offset <- 0 to 25 | |
} { | |
- assay(10 + offset, a + offset) | |
+ test(10 + offset, a + offset) | |
} | |
} | |
- test("offsetByCodePoints - invalid values") { | |
+ @Test def offsetByCodePointsInvalidValues(): Unit = { | |
val str1 = "<bad args>" | |
val arr1 = str1.toArray | |
- assertThrows[java.lang.NullPointerException] { | |
- Character.offsetByCodePoints(null.asInstanceOf[Array[Char]], | |
- 1, | |
- arr1.length, | |
- 0, | |
- 0) | |
- } | |
+ assertThrows(classOf[java.lang.NullPointerException], | |
+ Character.offsetByCodePoints(null.asInstanceOf[Array[Char]], | |
+ 1, | |
+ arr1.length, | |
+ 0, | |
+ 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, -1, arr1.length, 0, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, -1, arr1.length, 0, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 0, -1, 0, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 0, -1, 0, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 1, arr1.length, 2, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 1, arr1.length, 2, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 2, arr1.length, 1, 0) | |
- } | |
+ assertThrows(classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 2, arr1.length, 1, 0)) | |
- assertThrows[java.lang.StringIndexOutOfBoundsException] { | |
- Character.offsetByCodePoints(arr1, 2, arr1.length, arr1.length + 1, 0) | |
- } | |
+ assertThrows( | |
+ classOf[java.lang.StringIndexOutOfBoundsException], | |
+ Character.offsetByCodePoints(arr1, 2, arr1.length, arr1.length + 1, 0)) | |
} | |
- test("toLowerCase-low") { | |
+ @Test def toLowerCaseLow(): Unit = { | |
// low chars | |
- assert(toLowerCase('\n') equals '\n') | |
+ assertTrue(toLowerCase('\n') equals '\n') | |
} | |
- test("toLowerCase-ascii") { | |
+ @Test def toLowerCaseAscii(): Unit = { | |
// ascii chars | |
- assert(toLowerCase('A') equals 'a') | |
- assert(toLowerCase('a') equals 'a') | |
- assertNot(toLowerCase('a') equals 'A') | |
- assert(toLowerCase('F') equals 'f') | |
- assert(toLowerCase('Z') equals 'z') | |
+ assertTrue(toLowerCase('A') equals 'a') | |
+ assertTrue(toLowerCase('a') equals 'a') | |
+ assertFalse(toLowerCase('a') equals 'A') | |
+ assertTrue(toLowerCase('F') equals 'f') | |
+ assertTrue(toLowerCase('Z') equals 'z') | |
} | |
- test("toLowerCase-compat") { | |
+ @Test def toLowerCaseCompat(): Unit = { | |
// compat characters are directly from the DB | |
// (03F4,GREEK CAPITAL THETA SYMBOL,Lu,0,L,<compat> 0398,N,,03B8,) | |
- assert(toLowerCase(0x03F4) equals 0x03B8) | |
- assert(toLowerCase('Θ') equals 'θ') | |
+ assertTrue(toLowerCase(0x03F4) equals 0x03B8) | |
+ assertTrue(toLowerCase('Θ') equals 'θ') | |
// (2161,ROMAN NUMERAL TWO,Nl,0,L,<compat> 0049 0049,N,,2171,) | |
- assert(toLowerCase(0x2161) equals 0x2171) | |
+ assertTrue(toLowerCase(0x2161) equals 0x2171) | |
// check lower to lower | |
- assert(toLowerCase('µ') equals 'µ') | |
+ assertTrue(toLowerCase('µ') equals 'µ') | |
} | |
- test("toLowerCase-alt") { | |
+ @Test def toLowerCaseAlt(): Unit = { | |
// alternating upper and lower case | |
// (256,257,-1,0)(302,303,-1,2) | |
- assert(toLowerCase(256) equals 257) | |
- assert(toLowerCase(257) equals 257) | |
- assert(toLowerCase(258) equals 259) | |
- assert(toLowerCase(302) equals 303) | |
+ assertTrue(toLowerCase(256) equals 257) | |
+ assertTrue(toLowerCase(257) equals 257) | |
+ assertTrue(toLowerCase(258) equals 259) | |
+ assertTrue(toLowerCase(302) equals 303) | |
} | |
- test("toLowerCase-high") { | |
+ @Test def toLowerCaseHigh(): Unit = { | |
// high points | |
- assert(toLowerCase(65313) equals 65345) | |
- assert(toLowerCase(65338) equals 65370) | |
- assert(toLowerCase(65339) equals 65339) | |
+ assertTrue(toLowerCase(65313) equals 65345) | |
+ assertTrue(toLowerCase(65338) equals 65370) | |
+ assertTrue(toLowerCase(65339) equals 65339) | |
} | |
- test("toLowerCase-above") { | |
+ @Test def toLowerCaseAbove(): Unit = { | |
// top and above range | |
- assert(toLowerCase(0x10FFFF) equals 0x10FFFF) | |
- assert(toLowerCase(0x110000) equals 0x110000) | |
+ assertTrue(toLowerCase(0x10FFFF) equals 0x10FFFF) | |
+ assertTrue(toLowerCase(0x110000) equals 0x110000) | |
} | |
- test("toUpperCase-low") { | |
+ @Test def toUpperCaseLow(): Unit = { | |
// low chars | |
- assert(toUpperCase('\n') equals '\n') | |
+ assertTrue(toUpperCase('\n') equals '\n') | |
} | |
- test("toUpperCase-ascii") { | |
+ @Test def toUpperCaseAscii(): Unit = { | |
// ascii chars | |
- assert(toUpperCase('a') equals 'A') | |
- assert(toUpperCase('A') equals 'A') | |
- assertNot(toUpperCase('A') equals 'a') | |
- assert(toUpperCase('f') equals 'F') | |
- assert(toUpperCase('z') equals 'Z') | |
+ assertTrue(toUpperCase('a') equals 'A') | |
+ assertTrue(toUpperCase('A') equals 'A') | |
+ assertFalse(toUpperCase('A') equals 'a') | |
+ assertTrue(toUpperCase('f') equals 'F') | |
+ assertTrue(toUpperCase('z') equals 'Z') | |
} | |
- test("toUpperCase-compat") { | |
+ @Test def toUpperCaseCompat(): Unit = { | |
// compat characters are directly from the DB | |
// (03D0,GREEK BETA SYMBOL,Ll,0,L,<compat> 03B2,N,0392,,0392) | |
- assert(toUpperCase(0x03D0) equals 0x0392) | |
- assert(toUpperCase('β') equals 'Β') | |
+ assertTrue(toUpperCase(0x03D0) equals 0x0392) | |
+ assertTrue(toUpperCase('β') equals 'Β') | |
// (00B5,MICRO SIGN,Ll,0,L,<compat> 03BC,N,039C,,039C) | |
- assert(toUpperCase(0x00B5) equals 0x039C) | |
- assert(toUpperCase('μ') equals 'Μ') | |
+ assertTrue(toUpperCase(0x00B5) equals 0x039C) | |
+ assertTrue(toUpperCase('μ') equals 'Μ') | |
} | |
- test("toUpperCase-alt") { | |
+ @Test def toUpperCaseAlt(): Unit = { | |
// alternating upper and lower case | |
// (257,256,1,0)(303,302,1,2) | |
- assert(toUpperCase(257) equals 256) | |
- assert(toUpperCase(258) equals 258) | |
- assert(toUpperCase(259) equals 258) | |
- assert(toUpperCase(303) equals 302) | |
+ assertTrue(toUpperCase(257) equals 256) | |
+ assertTrue(toUpperCase(258) equals 258) | |
+ assertTrue(toUpperCase(259) equals 258) | |
+ assertTrue(toUpperCase(303) equals 302) | |
} | |
- test("toUpperCase-high") { | |
+ @Test def toUpperCaseHigh(): Unit = { | |
// high points | |
// (65345,65313,32,0)(65370,65338,32,1) | |
// (66600,66560,40,0)(66639,66599,40,1) | |
// (71872,71840,32,0)(71903,71871,32,1) | |
- assert(toUpperCase(65345) equals 65313) | |
- assert(toUpperCase(65370) equals 65338) | |
- assert(toUpperCase(66600) equals 66560) | |
+ assertTrue(toUpperCase(65345) equals 65313) | |
+ assertTrue(toUpperCase(65370) equals 65338) | |
+ assertTrue(toUpperCase(66600) equals 66560) | |
} | |
- test("toUpperCase-above") { | |
+ @Test def toUpperCaseAbove(): Unit = { | |
// top and above range | |
- assert(toUpperCase(0x10FFFF) equals 0x10FFFF) | |
- assert(toUpperCase(0x110000) equals 0x110000) | |
+ assertTrue(toUpperCase(0x10FFFF) equals 0x10FFFF) | |
+ assertTrue(toUpperCase(0x110000) equals 0x110000) | |
} | |
- test("UnicodeBlock.of") { | |
- assert(UnicodeBlock.of('a') equals UnicodeBlock.BASIC_LATIN) | |
- assert(UnicodeBlock.of('א') equals UnicodeBlock.HEBREW) | |
+ @Test def unicodeBlockOf(): Unit = { | |
+ assertTrue(UnicodeBlock.of('a') equals UnicodeBlock.BASIC_LATIN) | |
+ assertTrue(UnicodeBlock.of('א') equals UnicodeBlock.HEBREW) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/DoubleSuite.scala b/unit-tests/src/test/scala/java/lang/DoubleTest.scala | |
index 696d0f1e..50b0d9cd 100644 | |
--- a/unit-tests/src/test/scala/java/lang/DoubleSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/DoubleTest.scala | |
@@ -7,236 +7,245 @@ import java.lang.Double.{ | |
toHexString | |
} | |
-object DoubleSuite extends tests.Suite { | |
- test("equals") { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class DoubleTest { | |
+ @Test def testEquals(): Unit = { | |
val pzero = +0.0 | |
val nzero = -0.0 | |
- assert(pzero equals pzero) | |
- assert(nzero equals nzero) | |
- assertNot(pzero equals nzero) | |
+ assertTrue(pzero equals pzero) | |
+ assertTrue(nzero equals nzero) | |
+ assertFalse(pzero equals nzero) | |
val szero = 1.0 - 1.0 | |
- assert(pzero equals szero) | |
+ assertTrue(pzero equals szero) | |
val bpzero: java.lang.Double = pzero | |
val bnzero: java.lang.Double = nzero | |
- assertNot(bpzero equals bnzero) | |
+ assertFalse(bpzero equals bnzero) | |
val bszero: java.lang.Double = szero | |
- assert(bpzero equals bszero) | |
+ assertTrue(bpzero equals bszero) | |
val num1 = 123.45 | |
val num2 = 123.45 | |
- assert(num1 equals num2) | |
+ assertTrue(num1 equals num2) | |
val bnum1: java.lang.Double = num1 | |
val bnum2: java.lang.Double = num2 | |
- assert(bnum1 == bnum2) | |
+ assertTrue(bnum1 == bnum2) | |
val pmax1 = scala.Double.MaxValue | |
val pmax2 = scala.Double.MaxValue | |
- assert(pmax1 equals pmax2) | |
+ assertTrue(pmax1 equals pmax2) | |
val pmax3 = scala.Double.MaxValue + 1 | |
- assert(pmax1 equals pmax3) | |
+ assertTrue(pmax1 equals pmax3) | |
val bpmax1: java.lang.Double = scala.Double.MaxValue | |
val bpmax2: java.lang.Double = scala.Double.MaxValue | |
- assert(bpmax1 equals bpmax2) | |
+ assertTrue(bpmax1 equals bpmax2) | |
val bpmax3: java.lang.Double = scala.Double.MaxValue + 1 | |
- assert(bpmax1 equals bpmax3) | |
+ assertTrue(bpmax1 equals bpmax3) | |
val pmin1 = scala.Double.MinValue | |
val pmin2 = scala.Double.MinValue | |
- assert(pmin1 equals pmin2) | |
+ assertTrue(pmin1 equals pmin2) | |
val pmin3 = scala.Double.MinValue + 1 | |
- assert(pmin1 equals pmin3) | |
+ assertTrue(pmin1 equals pmin3) | |
val bpmin1: java.lang.Double = scala.Double.MinValue | |
val bpmin2: java.lang.Double = scala.Double.MinValue | |
- assert(bpmin1 equals bpmin2) | |
+ assertTrue(bpmin1 equals bpmin2) | |
val bpmin3: java.lang.Double = scala.Double.MinValue + 1 | |
- assert(bpmin1 equals bpmin3) | |
+ assertTrue(bpmin1 equals bpmin3) | |
val pinf1 = scala.Double.PositiveInfinity | |
val pinf2 = scala.Double.MaxValue + scala.Double.MaxValue | |
- assert(pinf1 equals pinf2) | |
+ assertTrue(pinf1 equals pinf2) | |
val bpinf1: java.lang.Double = pinf1 | |
val bpinf2: java.lang.Double = pinf2 | |
- assert(bpinf1 equals bpinf2) | |
+ assertTrue(bpinf1 equals bpinf2) | |
val ninf1 = scala.Double.NegativeInfinity | |
val ninf2 = scala.Double.MinValue + scala.Double.MinValue | |
- assert(ninf1 equals ninf2) | |
+ assertTrue(ninf1 equals ninf2) | |
val bninf1: java.lang.Double = ninf1 | |
val bninf2: java.lang.Double = ninf2 | |
- assert(bninf1 equals bninf2) | |
+ assertTrue(bninf1 equals bninf2) | |
- assert(Double.NaN equals Double.NaN) | |
+ assertTrue(Double.NaN equals Double.NaN) | |
val x = Double.NaN | |
val y = longBitsToDouble(doubleToRawLongBits(x) | 1) | |
- assert(x equals y) | |
+ assertTrue(x equals y) | |
val z = longBitsToDouble(doubleToLongBits(x) | 1) | |
- assert(x equals z) | |
+ assertTrue(x equals z) | |
} | |
- test("==") { | |
+ @Test def testEqualEqual(): Unit = { | |
val pzero = +0.0 | |
val nzero = -0.0 | |
- assert(pzero == pzero) | |
- assert(nzero == nzero) | |
- assert(pzero == nzero) | |
+ assertTrue(pzero == pzero) | |
+ assertTrue(nzero == nzero) | |
+ assertTrue(pzero == nzero) | |
val szero = 1.0 - 1.0 | |
- assert(pzero == szero) | |
+ assertTrue(pzero == szero) | |
val bpzero: Any = pzero | |
val bnzero: Any = nzero | |
- assert(bpzero == bnzero) | |
+ assertTrue(bpzero == bnzero) | |
val bszero: java.lang.Double = szero | |
- assert(bpzero == bszero) | |
+ assertTrue(bpzero == bszero) | |
val num1 = 123.45 | |
val num2 = 123.45 | |
- assert(num1 == num2) | |
+ assertTrue(num1 == num2) | |
val bnum1: java.lang.Double = num1 | |
val bnum2: java.lang.Double = num2 | |
- assert(bnum1 == bnum2) | |
+ assertTrue(bnum1 == bnum2) | |
val pmax1 = scala.Double.MaxValue | |
val pmax2 = scala.Double.MaxValue | |
- assert(pmax1 == pmax2) | |
+ assertTrue(pmax1 == pmax2) | |
val pmax3 = scala.Double.MaxValue + 1 | |
- assert(pmax1 == pmax3) | |
+ assertTrue(pmax1 == pmax3) | |
val bpmax1: java.lang.Double = scala.Double.MaxValue | |
val bpmax2: java.lang.Double = scala.Double.MaxValue | |
- assert(bpmax1 == bpmax2) | |
+ assertTrue(bpmax1 == bpmax2) | |
val bpmax3: java.lang.Double = scala.Double.MaxValue + 1 | |
- assert(bpmax1 == bpmax3) | |
+ assertTrue(bpmax1 == bpmax3) | |
val pmin1 = scala.Double.MinValue | |
val pmin2 = scala.Double.MinValue | |
- assert(pmin1 == pmin2) | |
+ assertTrue(pmin1 == pmin2) | |
val pmin3 = scala.Double.MinValue + 1 | |
- assert(pmin1 == pmin3) | |
+ assertTrue(pmin1 == pmin3) | |
val bpmin1: java.lang.Double = scala.Double.MinValue | |
val bpmin2: java.lang.Double = scala.Double.MinValue | |
- assert(bpmin1 == bpmin2) | |
+ assertTrue(bpmin1 == bpmin2) | |
val bpmin3: java.lang.Double = scala.Double.MinValue + 1 | |
- assert(bpmin1 == bpmin3) | |
+ assertTrue(bpmin1 == bpmin3) | |
val pinf1 = scala.Double.PositiveInfinity | |
val pinf2 = scala.Double.MaxValue + scala.Double.MaxValue | |
- assert(pinf1 == pinf2) | |
+ assertTrue(pinf1 == pinf2) | |
val bpinf1: java.lang.Double = pinf1 | |
val bpinf2: java.lang.Double = pinf2 | |
- assert(bpinf1 == bpinf2) | |
+ assertTrue(bpinf1 == bpinf2) | |
val ninf1 = scala.Double.NegativeInfinity | |
val ninf2 = scala.Double.MinValue + scala.Double.MinValue | |
- assert(ninf1 == ninf2) | |
+ assertTrue(ninf1 == ninf2) | |
val bninf1: java.lang.Double = ninf1 | |
val bninf2: java.lang.Double = ninf2 | |
- assert(bninf1 == bninf2) | |
+ assertTrue(bninf1 == bninf2) | |
- assertNot(Double.NaN == Double.NaN) | |
+ assertFalse(Double.NaN == Double.NaN) | |
val x = Double.NaN | |
val y = longBitsToDouble(doubleToRawLongBits(x) | 1) | |
- assertNot(x == y) | |
+ assertFalse(x == y) | |
val z = longBitsToDouble(doubleToLongBits(x) | 1) | |
- assertNot(x == z) | |
+ assertFalse(x == z) | |
} | |
- test("eq") { | |
+ @Test def testEq(): Unit = { | |
val bpzero: java.lang.Double = +0.0 | |
val bnzero: java.lang.Double = -0.0 | |
- assert(bpzero eq bpzero) | |
- assert(bnzero eq bnzero) | |
- assertNot(bpzero eq bnzero) | |
+ assertTrue(bpzero eq bpzero) | |
+ assertTrue(bnzero eq bnzero) | |
+ assertFalse(bpzero eq bnzero) | |
val bszero: java.lang.Double = 1.0 - 1.0 | |
- assertNot(bpzero eq bszero) | |
+ assertFalse(bpzero eq bszero) | |
val bnum1: java.lang.Double = 123.45 | |
val bnum2: java.lang.Double = 123.45 | |
- assertNot(bnum1 eq bnum2) | |
+ assertFalse(bnum1 eq bnum2) | |
val bpmax1: java.lang.Double = scala.Double.MaxValue | |
val bpmax2: java.lang.Double = scala.Double.MaxValue | |
- assertNot(bpmax1 eq bpmax2) | |
+ assertFalse(bpmax1 eq bpmax2) | |
val bpmax3: java.lang.Double = scala.Double.MaxValue + 1 | |
- assertNot(bpmax1 eq bpmax3) | |
+ assertFalse(bpmax1 eq bpmax3) | |
val bpmin1: java.lang.Double = scala.Double.MinValue | |
val bpmin2: java.lang.Double = scala.Double.MinValue | |
- assertNot(bpmin1 eq bpmin2) | |
+ assertFalse(bpmin1 eq bpmin2) | |
val bpmin3: java.lang.Double = scala.Double.MinValue + 1 | |
- assertNot(bpmin1 eq bpmin3) | |
+ assertFalse(bpmin1 eq bpmin3) | |
val bpinf1: java.lang.Double = scala.Double.PositiveInfinity | |
val bpinf2: java.lang.Double = scala.Double.MaxValue + scala.Double.MaxValue | |
- assertNot(bpinf1 eq bpinf2) | |
+ assertFalse(bpinf1 eq bpinf2) | |
val bninf1: java.lang.Double = scala.Double.NegativeInfinity | |
val bninf2: java.lang.Double = scala.Double.MinValue + scala.Double.MinValue | |
- assertNot(bninf1 eq bninf2) | |
+ assertFalse(bninf1 eq bninf2) | |
} | |
- test("parseDouble") { | |
- assert(Double.parseDouble("1.0") == 1.0) | |
- assert(Double.parseDouble("-1.0") == -1.0) | |
- assert(Double.parseDouble("0.0") == 0.0) | |
- assert(Double.parseDouble("-0.0") == -0.0) | |
- assert(Double.parseDouble("Infinity") == Double.POSITIVE_INFINITY) | |
- assert(Double.parseDouble("-Infinity") == Double.NEGATIVE_INFINITY) | |
- assert(Double.isNaN(Double.parseDouble("NaN"))) | |
+ @Test def parseDouble(): Unit = { | |
+ assertTrue(Double.parseDouble("1.0") == 1.0) | |
+ assertTrue(Double.parseDouble("-1.0") == -1.0) | |
+ assertTrue(Double.parseDouble("0.0") == 0.0) | |
+ assertTrue(Double.parseDouble("-0.0") == -0.0) | |
+ assertTrue(Double.parseDouble("Infinity") == Double.POSITIVE_INFINITY) | |
+ assertTrue(Double.parseDouble("-Infinity") == Double.NEGATIVE_INFINITY) | |
+ assertTrue(Double.isNaN(Double.parseDouble("NaN"))) | |
- assert(Double.parseDouble("6.66D") == 6.66, "a8") | |
+ assertTrue("a8", Double.parseDouble("6.66D") == 6.66) | |
// Java allows trailing whitespace, including tabs & nulls. | |
- assert(Double.parseDouble("6.66D\t ") == 6.66, "a9") | |
- assert(Double.parseDouble("6.66D\u0000") == 6.66, "a9a") | |
+ assertTrue("a9", Double.parseDouble("6.66D\t ") == 6.66) | |
+ assertTrue("a9a", Double.parseDouble("6.66D\u0000") == 6.66) | |
- assert(Double.parseDouble("6.66d") == 6.66, "a10") | |
+ assertTrue("a10", Double.parseDouble("6.66d") == 6.66) | |
- assert(Double.parseDouble("7.77F") == 7.77, "a11") | |
- assert(Double.parseDouble("7.77f") == 7.77, "a12") | |
+ assertTrue("a11", Double.parseDouble("7.77F") == 7.77) | |
+ assertTrue("a12", Double.parseDouble("7.77f") == 7.77) | |
// Does not parse characters beyond IEEE754 spec. | |
- assert(Double.parseDouble("1.7976931348623157999999999") | |
- == 1.7976931348623157, | |
- "a13") | |
- | |
- assertThrows[NumberFormatException](Double.parseDouble("")) | |
- assertThrows[NumberFormatException](Double.parseDouble("D")) | |
- assertThrows[NumberFormatException](Double.parseDouble("potato")) | |
- assertThrows[NumberFormatException](Double.parseDouble("0.0potato")) | |
- assertThrows[NumberFormatException](Double.parseDouble("0.potato")) | |
- | |
- assertThrows[NumberFormatException](Double.parseDouble("6.66 D")) | |
- assertThrows[NumberFormatException](Double.parseDouble("6.66D Bad ")) | |
- assertThrows[NumberFormatException](Double.parseDouble("6.66D\u0000a")) | |
- assertThrows[NumberFormatException](Double.parseDouble("6.66D \u0100")) | |
+ assertTrue("a13", | |
+ Double.parseDouble("1.7976931348623157999999999") | |
+ == 1.7976931348623157) | |
+ | |
+ assertThrows(classOf[NumberFormatException], Double.parseDouble("")) | |
+ assertThrows(classOf[NumberFormatException], Double.parseDouble("D")) | |
+ assertThrows(classOf[NumberFormatException], Double.parseDouble("potato")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Double.parseDouble("0.0potato")) | |
+ assertThrows(classOf[NumberFormatException], Double.parseDouble("0.potato")) | |
+ | |
+ assertThrows(classOf[NumberFormatException], Double.parseDouble("6.66 D")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Double.parseDouble("6.66D Bad ")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Double.parseDouble("6.66D\u0000a")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Double.parseDouble("6.66D \u0100")) | |
// Out of IEE754 range handling | |
// Too big - java.lang.Double.MAX_VALUE times 10 | |
- assert(Double.parseDouble("1.7976931348623157E309") == | |
- Double.POSITIVE_INFINITY, | |
- "a20") | |
+ assertTrue("a20", | |
+ Double.parseDouble("1.7976931348623157E309") == | |
+ Double.POSITIVE_INFINITY) | |
// Too big - Negative java.lang.Double.MAX_VALUE times 10 | |
- assert(Double.parseDouble("-1.7976931348623157E309") == | |
- Double.NEGATIVE_INFINITY, | |
- "a21") | |
+ assertTrue("a21", | |
+ Double.parseDouble("-1.7976931348623157E309") == | |
+ Double.NEGATIVE_INFINITY) | |
// Too close to 0 - java.lang.Double.MIN_VALUE divided by 10 | |
- assert(Double.parseDouble("4.9E-325") == 0.0, "a22") | |
+ assertTrue("a22", Double.parseDouble("4.9E-325") == 0.0) | |
// Scala Native Issue #1836, a string Too Big reported from the wild. | |
val a = "-274672389457236457826542634627345697228374687236476867674746" + | |
@@ -245,25 +254,25 @@ object DoubleSuite extends tests.Suite { | |
"7384567845678658734587364576745683475674576345786348576847567846578" + | |
"3456702897830296720476846578634576384567845678346573465786457863" | |
- assert(Double.parseDouble(a) == Double.NEGATIVE_INFINITY, "a23") | |
+ assertTrue("a23", Double.parseDouble(a) == Double.NEGATIVE_INFINITY) | |
// Hexadecimal strings | |
- assert(Double.parseDouble("0x0p1") == 0.0f, "a30") | |
- assert(Double.parseDouble("0x1p0") == 1.0f, "a31") | |
+ assertTrue("a30", Double.parseDouble("0x0p1") == 0.0f) | |
+ assertTrue("a31", Double.parseDouble("0x1p0") == 1.0f) | |
- assert(Double.parseDouble("0x1p1F") == 2.0f, "a32") | |
+ assertTrue("a32", Double.parseDouble("0x1p1F") == 2.0f) | |
- assert(Double.parseDouble("0x1.8eae14p6") == 99.67f, "a33") | |
- assert(Double.parseDouble("-0x1.8eae14p6") == -99.67f, "a34") | |
+ assertTrue("a33", Double.parseDouble("0x1.8eae14p6") == 99.67f) | |
+ assertTrue("a34", Double.parseDouble("-0x1.8eae14p6") == -99.67f) | |
} | |
// scala.Double passes -0.0d without change. j.l.Double gets forced to +0.0. | |
private def assertD2sEquals(expected: String, f: scala.Double): Unit = { | |
val result = f.toString | |
- assert(expected == result, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", expected == result) | |
} | |
- test("toString") { | |
+ @Test def testToString(): Unit = { | |
// Test non-finite values. | |
assertD2sEquals("Infinity", Double.POSITIVE_INFINITY) | |
@@ -296,21 +305,21 @@ object DoubleSuite extends tests.Suite { | |
assertD2sEquals("3.141592653589793E-4", (math.Pi * 1.0E-4)) | |
} | |
- test("toHexString - MIN_VALUE, Issue #1341") { | |
- assert( | |
+ @Test def toHexStringMinValueIssue1341(): Unit = { | |
+ assertTrue( | |
toHexString(java.lang.Double.MIN_VALUE).equals("0x0.0000000000001p-1022")) | |
} | |
- test("toHexString - assorted other values") { | |
+ @Test def toHexStringAssortedOtherValues(): Unit = { | |
- assert( | |
+ assertTrue( | |
toHexString(java.lang.Double.MAX_VALUE).equals("0x1.fffffffffffffp1023")) | |
// A value > 1.0 requiring lots of, but not all, zeros. | |
- assert(toHexString(1.00000000000003).equals("0x1.0000000000087p0")) | |
+ assertTrue(toHexString(1.00000000000003).equals("0x1.0000000000087p0")) | |
// An arbitrary but negative value. | |
- assert(java.lang.Double.toHexString(-31.0).equals("-0x1.fp4")) | |
+ assertTrue(java.lang.Double.toHexString(-31.0).equals("-0x1.fp4")) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/StringBuilderSuite.scala b/unit-tests/src/test/scala/java/lang/StringBuilderTest.scala | |
index 72fd7a77..0727d0f6 100644 | |
--- a/unit-tests/src/test/scala/java/lang/StringBuilderSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/StringBuilderTest.scala | |
@@ -2,7 +2,12 @@ package java.lang | |
// Ported from Scala.js | |
-object StringBuilderSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class StringBuilderTest { | |
def newBuilder: java.lang.StringBuilder = | |
new java.lang.StringBuilder | |
@@ -10,7 +15,7 @@ object StringBuilderSuite extends tests.Suite { | |
def initBuilder(str: String): java.lang.StringBuilder = | |
new java.lang.StringBuilder(str) | |
- test("append") { | |
+ @Test def append(): Unit = { | |
assertEquals("asdf", newBuilder.append("asdf").toString) | |
assertEquals("null", newBuilder.append(null: AnyRef).toString) | |
assertEquals("null", newBuilder.append(null: String).toString) | |
@@ -25,12 +30,12 @@ object StringBuilderSuite extends tests.Suite { | |
assertEquals("100000", newBuilder.append(100000).toString) | |
} | |
- test("append float") { | |
+ @Test def appendFloat(): Unit = { | |
assertEquals("2.5", newBuilder.append(2.5f).toString) | |
assertEquals("3.5", newBuilder.append(3.5).toString) | |
} | |
- test("insert") { | |
+ @Test def insert(): Unit = { | |
assertEquals("asdf", newBuilder.insert(0, "asdf").toString) | |
assertEquals("null", newBuilder.insert(0, null: AnyRef).toString) | |
assertEquals("null", newBuilder.insert(0, null: String).toString) | |
@@ -62,21 +67,22 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("abcd").insert(5, "whatever")) | |
} | |
- test("insert float") { | |
+ @Test def insertFloat(): Unit = { | |
assertEquals("2.5", newBuilder.insert(0, 2.5f).toString) | |
assertEquals("3.5", newBuilder.insert(0, 3.5).toString) | |
} | |
- // TODO: segfaults with EXC_BAD_ACCESS (code=1, address=0x0) | |
- // testFails("insert string builder", issue = -1) { | |
- // assertEquals("abcdef", initBuilder("abef").insert(2, initBuilder("abcde"), 2, 4).toString) | |
- // } | |
+ @Test def insertStringBuilder(): Unit = { | |
+ assertEquals( | |
+ "abcdef", | |
+ initBuilder("abef").insert(2, initBuilder("abcde"), 2, 4).toString) | |
+ } | |
- test("should_allow_string_interpolation_to_survive_null_and_undefined") { | |
+ @Test def shouldAllowStringInterpolationToSurviveNullAndUndefined(): Unit = { | |
assertEquals("null", s"${null}") | |
} | |
- test("deleteCharAt") { | |
+ @Test def deleteCharAt(): Unit = { | |
assertEquals("023", initBuilder("0123").deleteCharAt(1).toString) | |
assertEquals("123", initBuilder("0123").deleteCharAt(0).toString) | |
assertEquals("012", initBuilder("0123").deleteCharAt(3).toString) | |
@@ -86,7 +92,7 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("0123").deleteCharAt(4)) | |
} | |
- test("replace") { | |
+ @Test def replace(): Unit = { | |
assertEquals("0bc3", initBuilder("0123").replace(1, 3, "bc").toString) | |
assertEquals("abcd", initBuilder("0123").replace(0, 4, "abcd").toString) | |
assertEquals("abcd", initBuilder("0123").replace(0, 10, "abcd").toString) | |
@@ -99,7 +105,7 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("0123").replace(-1, 3, "x")) | |
} | |
- test("setCharAt") { | |
+ @Test def setCharAt(): Unit = { | |
val b = newBuilder | |
b.append("foobar") | |
@@ -113,12 +119,12 @@ object StringBuilderSuite extends tests.Suite { | |
expectThrows(classOf[StringIndexOutOfBoundsException], b.setCharAt(6, 'h')) | |
} | |
- test("ensureCapacity") { | |
+ @Test def ensureCapacity(): Unit = { | |
// test that ensureCapacity is linking | |
newBuilder.ensureCapacity(10) | |
} | |
- test("should_properly_setLength") { | |
+ @Test def shouldProperlySetLength(): Unit = { | |
val b = newBuilder | |
b.append("foobar") | |
@@ -128,7 +134,7 @@ object StringBuilderSuite extends tests.Suite { | |
assertEquals("foo\u0000\u0000\u0000", { b.setLength(6); b.toString }) | |
} | |
- test("appendCodePoint") { | |
+ @Test def appendCodePoint(): Unit = { | |
val b = newBuilder | |
b.appendCodePoint(0x61) | |
assertEquals("a", b.toString) | |
diff --git a/unit-tests/src/test/scala/java/lang/StringBuilderSuite.scala b/unit-tests/src/test/scala/java/lang/StringBuilderTest.scala | |
index 72fd7a77..0727d0f6 100644 | |
--- a/unit-tests/src/test/scala/java/lang/StringBuilderSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/StringBuilderTest.scala | |
@@ -2,7 +2,12 @@ package java.lang | |
// Ported from Scala.js | |
-object StringBuilderSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class StringBuilderTest { | |
def newBuilder: java.lang.StringBuilder = | |
new java.lang.StringBuilder | |
@@ -10,7 +15,7 @@ object StringBuilderSuite extends tests.Suite { | |
def initBuilder(str: String): java.lang.StringBuilder = | |
new java.lang.StringBuilder(str) | |
- test("append") { | |
+ @Test def append(): Unit = { | |
assertEquals("asdf", newBuilder.append("asdf").toString) | |
assertEquals("null", newBuilder.append(null: AnyRef).toString) | |
assertEquals("null", newBuilder.append(null: String).toString) | |
@@ -25,12 +30,12 @@ object StringBuilderSuite extends tests.Suite { | |
assertEquals("100000", newBuilder.append(100000).toString) | |
} | |
- test("append float") { | |
+ @Test def appendFloat(): Unit = { | |
assertEquals("2.5", newBuilder.append(2.5f).toString) | |
assertEquals("3.5", newBuilder.append(3.5).toString) | |
} | |
- test("insert") { | |
+ @Test def insert(): Unit = { | |
assertEquals("asdf", newBuilder.insert(0, "asdf").toString) | |
assertEquals("null", newBuilder.insert(0, null: AnyRef).toString) | |
assertEquals("null", newBuilder.insert(0, null: String).toString) | |
@@ -62,21 +67,22 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("abcd").insert(5, "whatever")) | |
} | |
- test("insert float") { | |
+ @Test def insertFloat(): Unit = { | |
assertEquals("2.5", newBuilder.insert(0, 2.5f).toString) | |
assertEquals("3.5", newBuilder.insert(0, 3.5).toString) | |
} | |
- // TODO: segfaults with EXC_BAD_ACCESS (code=1, address=0x0) | |
- // testFails("insert string builder", issue = -1) { | |
- // assertEquals("abcdef", initBuilder("abef").insert(2, initBuilder("abcde"), 2, 4).toString) | |
- // } | |
+ @Test def insertStringBuilder(): Unit = { | |
+ assertEquals( | |
+ "abcdef", | |
+ initBuilder("abef").insert(2, initBuilder("abcde"), 2, 4).toString) | |
+ } | |
- test("should_allow_string_interpolation_to_survive_null_and_undefined") { | |
+ @Test def shouldAllowStringInterpolationToSurviveNullAndUndefined(): Unit = { | |
assertEquals("null", s"${null}") | |
} | |
- test("deleteCharAt") { | |
+ @Test def deleteCharAt(): Unit = { | |
assertEquals("023", initBuilder("0123").deleteCharAt(1).toString) | |
assertEquals("123", initBuilder("0123").deleteCharAt(0).toString) | |
assertEquals("012", initBuilder("0123").deleteCharAt(3).toString) | |
@@ -86,7 +92,7 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("0123").deleteCharAt(4)) | |
} | |
- test("replace") { | |
+ @Test def replace(): Unit = { | |
assertEquals("0bc3", initBuilder("0123").replace(1, 3, "bc").toString) | |
assertEquals("abcd", initBuilder("0123").replace(0, 4, "abcd").toString) | |
assertEquals("abcd", initBuilder("0123").replace(0, 10, "abcd").toString) | |
@@ -99,7 +105,7 @@ object StringBuilderSuite extends tests.Suite { | |
initBuilder("0123").replace(-1, 3, "x")) | |
} | |
- test("setCharAt") { | |
+ @Test def setCharAt(): Unit = { | |
val b = newBuilder | |
b.append("foobar") | |
@@ -113,12 +119,12 @@ object StringBuilderSuite extends tests.Suite { | |
expectThrows(classOf[StringIndexOutOfBoundsException], b.setCharAt(6, 'h')) | |
} | |
- test("ensureCapacity") { | |
+ @Test def ensureCapacity(): Unit = { | |
// test that ensureCapacity is linking | |
newBuilder.ensureCapacity(10) | |
} | |
- test("should_properly_setLength") { | |
+ @Test def shouldProperlySetLength(): Unit = { | |
val b = newBuilder | |
b.append("foobar") | |
@@ -128,7 +134,7 @@ object StringBuilderSuite extends tests.Suite { | |
assertEquals("foo\u0000\u0000\u0000", { b.setLength(6); b.toString }) | |
} | |
- test("appendCodePoint") { | |
+ @Test def appendCodePoint(): Unit = { | |
val b = newBuilder | |
b.appendCodePoint(0x61) | |
assertEquals("a", b.toString) | |
diff --git a/unit-tests/src/test/scala/java/lang/ProcessSuite.scala b/unit-tests/src/test/scala/java/lang/ProcessTest.scala | |
index b795332b..7fb28e9f 100644 | |
--- a/unit-tests/src/test/scala/java/lang/ProcessSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/ProcessTest.scala | |
@@ -9,7 +9,11 @@ import scala.scalanative.unsafe._ | |
import scala.scalanative.posix.{fcntl, unistd} | |
import scala.io.Source | |
-object ProcessSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+class ProcessTest { | |
+ import ProcessUtils._ | |
private def assertProcessExitOrTimeout(process: Process): Unit = { | |
// Suspend execution of the test until either the specified | |
@@ -29,32 +33,22 @@ object ProcessSuite extends tests.Suite { | |
val tmo = 5 | |
val tmUnit = TimeUnit.SECONDS | |
- assert(process.waitFor(tmo, tmUnit), | |
- s"Process took more than $tmo ${tmUnit.name} to exit.") | |
- } | |
- | |
- def readInputStream(s: InputStream) = Source.fromInputStream(s).mkString | |
- | |
- val resourceDir = | |
- s"${System.getProperty("user.dir")}/unit-tests/src/test/resources/process" | |
- | |
- // This makes it easy to decorate the test for debugging | |
- def addTest[R](name: String)(f: => R): Unit = test(name) { | |
- f | |
+ assertTrue(s"Process took more than $tmo ${tmUnit.name} to exit.", | |
+ process.waitFor(tmo, tmUnit)) | |
} | |
val scripts = Set("echo.sh", "err.sh", "ls", "hello.sh") | |
- addTest("ls") { | |
+ @Test def ls(): Unit = { | |
val proc = new ProcessBuilder("ls", resourceDir).start() | |
val out = readInputStream(proc.getInputStream) | |
assertProcessExitOrTimeout(proc) | |
- assert(out.split("\n").toSet == scripts) | |
+ assertTrue(out.split("\n").toSet == scripts) | |
} | |
- addTest("inherit") { | |
+ @Test def inherit(): Unit = { | |
val f = Files.createTempFile("/tmp", "out") | |
val savedFD = unistd.dup(unistd.STDOUT_FILENO) | |
val flags = fcntl.O_RDWR | fcntl.O_TRUNC | fcntl.O_CREAT | |
@@ -72,7 +66,7 @@ object ProcessSuite extends tests.Suite { | |
unistd.dup2(savedFD, unistd.STDOUT_FILENO) | |
fcntl.close(savedFD) | |
} | |
- assert(out.split("\n").toSet == scripts) | |
+ assertTrue(out.split("\n").toSet == scripts) | |
} | |
private def checkPathOverride(pb: ProcessBuilder) = { | |
@@ -81,22 +75,22 @@ object ProcessSuite extends tests.Suite { | |
assertProcessExitOrTimeout(proc) | |
- assert(out == "1") | |
+ assertTrue(out == "1") | |
} | |
- addTest("PATH override") { | |
+ @Test def pathOverride(): Unit = { | |
val pb = new ProcessBuilder("ls", resourceDir) | |
pb.environment.put("PATH", resourceDir) | |
checkPathOverride(pb) | |
} | |
- addTest("PATH prefix override") { | |
+ @Test def pathPrefixOverride(): Unit = { | |
val pb = new ProcessBuilder("ls", resourceDir) | |
pb.environment.put("PATH", s"$resourceDir:${pb.environment.get("PATH")}") | |
checkPathOverride(pb) | |
} | |
- addTest("input and error stream") { | |
+ @Test def inputAndErrorStream(): Unit = { | |
val pb = new ProcessBuilder("err.sh") | |
val cwd = System.getProperty("user.dir") | |
pb.environment.put("PATH", s"$cwd/unit-tests/src/test/resources/process") | |
@@ -104,11 +98,11 @@ object ProcessSuite extends tests.Suite { | |
assertProcessExitOrTimeout(proc) | |
- assert(readInputStream(proc.getErrorStream) == "foo") | |
- assert(readInputStream(proc.getInputStream) == "bar") | |
+ assertTrue(readInputStream(proc.getErrorStream) == "foo") | |
+ assertTrue(readInputStream(proc.getInputStream) == "bar") | |
} | |
- addTest("input stream writes to file") { | |
+ @Test def inputStreamWritesToFile(): Unit = { | |
val pb = new ProcessBuilder("echo.sh") | |
pb.environment.put("PATH", resourceDir) | |
val file = File.createTempFile("istest", ".tmp", new File("/tmp")) | |
@@ -122,13 +116,13 @@ object ProcessSuite extends tests.Suite { | |
assertProcessExitOrTimeout(proc) | |
val out = Source.fromFile(file.toString).getLines mkString "\n" | |
- assert(out == "hello") | |
+ assertTrue(out == "hello") | |
} finally { | |
file.delete() | |
} | |
} | |
- addTest("output stream reads from file") { | |
+ @Test def outputStreamReadsFromFile(): Unit = { | |
val pb = new ProcessBuilder("echo.sh") | |
pb.environment.put("PATH", resourceDir) | |
val file = File.createTempFile("istest", ".tmp", new File("/tmp")) | |
@@ -142,13 +136,13 @@ object ProcessSuite extends tests.Suite { | |
assertProcessExitOrTimeout(proc) | |
val out = readInputStream(proc.getInputStream) | |
- assert(out == "hello") | |
+ assertTrue(out == "hello") | |
} finally { | |
file.delete() | |
} | |
} | |
- addTest("redirectErrorStream") { | |
+ @Test def redirectErrorStream(): Unit = { | |
val pb = new ProcessBuilder("err.sh") | |
val cwd = System.getProperty("user.dir") | |
pb.environment.put("PATH", s"$cwd/unit-tests/src/test/resources/process") | |
@@ -159,21 +153,21 @@ object ProcessSuite extends tests.Suite { | |
val out = readInputStream(proc.getInputStream) | |
val err = readInputStream(proc.getErrorStream) | |
- assert(out == "foobar") | |
- assert(err == "") | |
+ assertTrue(out == "foobar") | |
+ assertTrue(err == "") | |
} | |
- addTest("waitFor with timeout completes") { | |
+ @Test def waitForWithTimeoutCompletes(): Unit = { | |
val proc = new ProcessBuilder("sleep", "0.001").start() | |
- assert(proc.waitFor(1, TimeUnit.SECONDS)) | |
- assert(proc.exitValue == 0) | |
+ assertTrue(proc.waitFor(1, TimeUnit.SECONDS)) | |
+ assertTrue(proc.exitValue == 0) | |
} | |
// Design Note: | |
// The timing on the next few tests is pretty tight and subject | |
// to race conditions. The process is intended to take only 5 milliseconds | |
// overall. The waitFor(1. TimeUnit.MILLISECONDS) assumes that the | |
- // process has not lived its lifetime by the time the assert() | |
+ // process has not lived its lifetime by the time the assertTrue() | |
// executes, a race condition. Just because two instructions are | |
// right next to each other, does not mean they execute without | |
// intervening interruption or significant elapsed time. | |
@@ -183,30 +177,30 @@ object ProcessSuite extends tests.Suite { | |
// at least one Clang bug, so let it be until the race trips up | |
// someone else. | |
- addTest("waitFor with timeout times out") { | |
+ @Test def waitForWithTimeoutTimesOut(): Unit = { | |
val proc = new ProcessBuilder("sleep", "0.005").start() | |
- assert(!proc.waitFor(1, TimeUnit.MILLISECONDS)) | |
- assert(proc.isAlive) | |
+ assertTrue(!proc.waitFor(1, TimeUnit.MILLISECONDS)) | |
+ assertTrue(proc.isAlive) | |
proc.waitFor(1, TimeUnit.SECONDS) | |
} | |
- addTest("destroy") { | |
+ @Test def destroy(): Unit = { | |
val proc = new ProcessBuilder("sleep", "0.005").start() | |
- assert(proc.isAlive) | |
+ assertTrue(proc.isAlive) | |
proc.destroy() | |
- assert(proc.waitFor(100, TimeUnit.MILLISECONDS)) | |
- assert(proc.exitValue == 0x80 + 9) | |
+ assertTrue(proc.waitFor(100, TimeUnit.MILLISECONDS)) | |
+ assertTrue(proc.exitValue == 0x80 + 9) | |
} | |
- addTest("destroyForcibly") { | |
+ @Test def destroyForcibly(): Unit = { | |
val proc = new ProcessBuilder("sleep", "0.005").start() | |
- assert(proc.isAlive) | |
+ assertTrue(proc.isAlive) | |
val p = proc.destroyForcibly() | |
- assert(p.waitFor(100, TimeUnit.MILLISECONDS)) | |
- assert(p.exitValue == 0x80 + 9) | |
+ assertTrue(p.waitFor(100, TimeUnit.MILLISECONDS)) | |
+ assertTrue(p.exitValue == 0x80 + 9) | |
} | |
- addTest("shell fallback") { | |
+ @Test def shellFallback(): Unit = { | |
val pb = new ProcessBuilder("hello.sh") | |
pb.environment.put("PATH", resourceDir) | |
val proc = pb.start() | |
@@ -214,6 +208,6 @@ object ProcessSuite extends tests.Suite { | |
assertProcessExitOrTimeout(proc) | |
val out = readInputStream(proc.getInputStream) | |
- assert(out == "hello\n") | |
+ assertTrue(out == "hello\n") | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/StackTraceElementSuite.scala b/unit-tests/src/test/scala/java/lang/StackTraceElementTest.scala | |
index ddf3bdfa..53e85ac1 100644 | |
--- a/unit-tests/src/test/scala/java/lang/StackTraceElementSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/StackTraceElementTest.scala | |
@@ -1,5 +1,9 @@ | |
package java.lang | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+ | |
class StackTraceDummy1 @noinline() { | |
def dummy1: StackTraceElement = | |
(new Exception).getStackTrace | |
@@ -26,30 +30,30 @@ class StackTraceDummy4 @noinline() { | |
.head | |
} | |
-object StackTraceElementSuite extends tests.Suite { | |
+class StackTraceElementTest { | |
def dummy1 = (new StackTraceDummy1).dummy1 | |
def dummy2 = (new StackTraceDummy1)._dummy2 | |
def dummy3 = (new StackTraceDummy3_::).dummy3 | |
def dummy4 = (new StackTraceDummy4).dummy4 | |
- test("getClassName") { | |
- assert(dummy1.getClassName == "java.lang.StackTraceDummy1") | |
- assert(dummy2.getClassName == "java.lang.StackTraceDummy1") | |
- assert(dummy3.getClassName == "java.lang.StackTraceDummy3_$colon$colon") | |
- assert(dummy4.getClassName == "java.lang.StackTraceDummy4") | |
+ @Test def getClassName(): Unit = { | |
+ assertTrue(dummy1.getClassName == "java.lang.StackTraceDummy1") | |
+ assertTrue(dummy2.getClassName == "java.lang.StackTraceDummy1") | |
+ assertTrue(dummy3.getClassName == "java.lang.StackTraceDummy3_$colon$colon") | |
+ assertTrue(dummy4.getClassName == "java.lang.StackTraceDummy4") | |
} | |
- test("getMethodName") { | |
- assert(dummy1.getMethodName == "dummy1") | |
- assert(dummy2.getMethodName == "_dummy2") | |
- assert(dummy3.getMethodName == "dummy3") | |
- assert(dummy4.getMethodName == "<init>") | |
+ @Test def getMethodName(): Unit = { | |
+ assertTrue(dummy1.getMethodName == "dummy1") | |
+ assertTrue(dummy2.getMethodName == "_dummy2") | |
+ assertTrue(dummy3.getMethodName == "dummy3") | |
+ assertTrue(dummy4.getMethodName == "<init>") | |
} | |
- test("isNativeMethod") { | |
- assert(!dummy1.isNativeMethod) | |
- assert(!dummy2.isNativeMethod) | |
- assert(!dummy3.isNativeMethod) | |
- assert(!dummy4.isNativeMethod) | |
+ @Test def isNativeMethod(): Unit = { | |
+ assertFalse(dummy1.isNativeMethod) | |
+ assertFalse(dummy2.isNativeMethod) | |
+ assertFalse(dummy3.isNativeMethod) | |
+ assertFalse(dummy4.isNativeMethod) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/ThrowablesSuite.scala b/unit-tests/src/test/scala/java/lang/ThrowablesTest.scala | |
index b5a1d6c1..6ca27da5 100644 | |
--- a/unit-tests/src/test/scala/java/lang/ThrowablesSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/ThrowablesTest.scala | |
@@ -5,7 +5,12 @@ package java.lang | |
// | |
// The rest is an original contribution to Scala Native. | |
-object ThrowablesSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class ThrowablesTest { | |
// Consolidate boilerplate; aids consistency. | |
@@ -21,26 +26,26 @@ object ThrowablesSuite extends tests.Suite { | |
val expectedMessage = getThrowableMessage(expectedCause) | |
- assert(resultCause == expectedCause, | |
- s"cause: '${causeMessage}' != expected: '${expectedMessage}'") | |
+ assertTrue(s"cause: '${causeMessage}' != expected: '${expectedMessage}'", | |
+ resultCause == expectedCause) | |
} | |
private def checkMessage(throwable: Throwable, | |
expectedMessage: String): Unit = { | |
val resultMessage = throwable.getMessage | |
- assert(resultMessage == expectedMessage, | |
- s"message: '${resultMessage}' != expected: '${expectedMessage}'") | |
+ assertTrue(s"message: '${resultMessage}' != expected: '${expectedMessage}'", | |
+ resultMessage == expectedMessage) | |
} | |
private def checkStackTraceString(trace: String): Unit = { | |
val startText = "java.lang.Throwable" | |
- assert(trace.startsWith(startText), | |
- s"Expected trace to start with '${startText}' and it did not.") | |
+ assertTrue(s"Expected trace to start with '${startText}' and it did not.", | |
+ trace.startsWith(startText)) | |
val containsText = "\tat <none>.main(Unknown Source)" | |
- assert(trace.contains(containsText), | |
- s"Expected trace to contain '${containsText}' and it did not.") | |
+ assertTrue(s"Expected trace to contain '${containsText}' and it did not.", | |
+ trace.contains(containsText)) | |
} | |
private def checkStackTrace(throwable: Throwable): Unit = { | |
@@ -54,9 +59,9 @@ object ThrowablesSuite extends tests.Suite { | |
private def checkSuppressed(throwable: Throwable, expectedLength: Int) { | |
val getSuppressedLength = throwable.getSuppressed.length | |
- assert(getSuppressedLength == expectedLength, | |
- s"getSuppressed.length: ${getSuppressedLength} != " + | |
- s"expected: ${expectedLength}") | |
+ assertTrue(s"getSuppressed.length: ${getSuppressedLength} != " + | |
+ s"expected: ${expectedLength}", | |
+ getSuppressedLength == expectedLength) | |
} | |
private def checkConstructed(throwable: Throwable, | |
@@ -72,7 +77,7 @@ object ThrowablesSuite extends tests.Suite { | |
// Zero & two argument constructor tests will exercise cases where | |
// the rightmost two arguments are true. | |
- test("Throwable(message, cause, false, false)") { | |
+ @Test def throwableMessageCauseFalseFalse(): Unit = { | |
val expectedMessage = "Athchomar chomakea" | |
val expectedCause = new Throwable("Khal Drogo") | |
@@ -81,7 +86,7 @@ object ThrowablesSuite extends tests.Suite { | |
checkConstructed(throwable, expectedMessage, expectedCause, 0) | |
} | |
- test("Throwable(message)") { | |
+ @Test def throwableMessage(): Unit = { | |
val expectedMessage = "Hello World" | |
val expectedCause = null | |
@@ -90,7 +95,7 @@ object ThrowablesSuite extends tests.Suite { | |
checkConstructed(throwable, expectedMessage, expectedCause, 0) | |
} | |
- test("Throwable(cause)") { | |
+ @Test def throwableCause(): Unit = { | |
val expectedMessageStem = "Primum Mobile" | |
val expectedMessage = s"java.lang.Throwable: ${expectedMessageStem}" | |
@@ -101,7 +106,7 @@ object ThrowablesSuite extends tests.Suite { | |
checkConstructed(throwable, expectedMessage, expectedCause, 0) | |
} | |
- test("Throwable()") { | |
+ @Test def throwable(): Unit = { | |
val expectedMessage = null | |
val expectedCause = null | |
@@ -129,23 +134,23 @@ object ThrowablesSuite extends tests.Suite { | |
// | |
// This accounts for all thirteen methods. | |
- test("addSuppressed(exception) - invalid arguments") { | |
- assertThrows[java.lang.NullPointerException] { | |
+ @Test def addSuppressedExceptionInvalidArguments(): Unit = { | |
+ assertThrows(classOf[java.lang.NullPointerException], { | |
val throwable = new Throwable() | |
throwable.addSuppressed(null) | |
- } | |
+ }) | |
- assertThrows[java.lang.IllegalArgumentException] { | |
+ assertThrows(classOf[java.lang.IllegalArgumentException], { | |
val throwable = new Throwable("Expect IllegalArgumentException") | |
throwable.addSuppressed(throwable) | |
- } | |
+ }) | |
} | |
- test("addSuppressed(exception) - enabled == true") { | |
+ @Test def addSuppressedExceptionEnabledEqualsTrue(): Unit = { | |
val throwable = new Throwable() | |
val sl = throwable.getSuppressed().length | |
- assert(sl == 0, s"length: ${sl} != expected: 0") | |
+ assertTrue(s"length: ${sl} != expected: 0", sl == 0) | |
val suppressed1 = new IllegalArgumentException("suppressed_1") | |
val suppressed2 = new UnsupportedOperationException("suppressed_2") | |
@@ -154,58 +159,56 @@ object ThrowablesSuite extends tests.Suite { | |
// sets. | |
throwable.addSuppressed(suppressed1) | |
- assert(throwable.getSuppressed().toSet == Set(suppressed1), | |
- s"first suppressed set did not match expected") | |
+ assertTrue(s"first suppressed set did not match expected", | |
+ throwable.getSuppressed().toSet == Set(suppressed1)) | |
throwable.addSuppressed(suppressed2) | |
- assert(throwable.getSuppressed().toSet == Set(suppressed1, suppressed2), | |
- s"second suppressed set did not match expected") | |
+ assertTrue(s"second suppressed set did not match expected", | |
+ throwable.getSuppressed().toSet == Set(suppressed1, suppressed2)) | |
} | |
- test("addSuppressed(exception) - enabled == false") { | |
+ @Test def addSuppressedExceptionEnabledEqualsFalse(): Unit = { | |
val throwable = new Throwable(null, null, false, true) | |
val sl0 = throwable.getSuppressed().length | |
- assert(sl0 == 0, s"starting suppressed length: ${sl0} != expected: 0") | |
+ assertTrue(s"starting suppressed length: ${sl0} != expected: 0", sl0 == 0) | |
val suppressed1 = new IllegalArgumentException("suppressed_1") | |
val suppressed2 = new UnsupportedOperationException("suppressed_2") | |
throwable.addSuppressed(suppressed1) | |
val sl1 = throwable.getSuppressed().length | |
- assert(sl1 == 0, s"first suppressed length: ${sl1} != expected: 0") | |
+ assertTrue(s"first suppressed length: ${sl1} != expected: 0", sl1 == 0) | |
throwable.addSuppressed(suppressed2) | |
val sl2 = throwable.getSuppressed().length | |
- assert(sl2 == 0, s"second suppressed length: ${sl2} != expected: 0") | |
+ assertTrue(s"second suppressed length: ${sl2} != expected: 0", sl2 == 0) | |
} | |
- test("initCause(cause) - cases which throw an Exception") { | |
- assertThrows[java.lang.IllegalArgumentException] { | |
+ @Test def initCauseCauseCasesWhichThrowAnException(): Unit = { | |
+ assertThrows(classOf[java.lang.IllegalArgumentException], { | |
val throwable = new Throwable() | |
throwable.initCause(throwable) | |
- } | |
+ }) | |
- assertThrows[java.lang.IllegalStateException] { | |
+ assertThrows(classOf[java.lang.IllegalStateException], { | |
val throwable = new Throwable(new Throwable("Lyta-Zod")) | |
throwable.initCause(new Throwable("Jayna-Zod")) | |
- } | |
+ }) | |
locally { | |
val throwable = new Throwable() | |
throwable.initCause(new Throwable("Kem")) | |
- assertThrows[java.lang.IllegalStateException] { | |
- throwable.initCause(new Throwable("Cor-Vex")) | |
- } | |
+ assertThrows(classOf[java.lang.IllegalStateException], | |
+ throwable.initCause(new Throwable("Cor-Vex"))) | |
- assertThrows[java.lang.IllegalStateException] { | |
- throwable.initCause(new Throwable("Jor-El")) | |
- } | |
+ assertThrows(classOf[java.lang.IllegalStateException], | |
+ throwable.initCause(new Throwable("Jor-El"))) | |
} | |
} | |
- test("initCause(cause)") { | |
+ @Test def initCauseCause(): Unit = { | |
val throwable = new Throwable() | |
// Constructor test above has already verified that initial cause is null. | |
@@ -218,11 +221,11 @@ object ThrowablesSuite extends tests.Suite { | |
val resultMsg = if (result == null) "null" else result.getMessage | |
- assert(result == cause, | |
- s"unexpected cause: '${resultMsg}' != expected: '${causeMsg}'") | |
+ assertTrue(s"unexpected cause: '${resultMsg}' != expected: '${causeMsg}'", | |
+ result == cause) | |
} | |
- test("printStackTrace(PrintStream)") { | |
+ @Test def printStackTracePrintStream(): Unit = { | |
val throwable = new Throwable("Dev-Em") | |
val baos = new java.io.ByteArrayOutputStream | |
val ps = new java.io.PrintStream(baos) | |
@@ -233,26 +236,28 @@ object ThrowablesSuite extends tests.Suite { | |
checkStackTraceString(baos.toString(encoding)) | |
} | |
- test("setStackTrace(stackTrace) - invalid arguments") { | |
- assertThrows[java.lang.NullPointerException] { | |
+ @Test def setStackTraceStackTraceInvalidArguments(): Unit = { | |
+ assertThrows(classOf[java.lang.NullPointerException], { | |
val throwable = new Throwable() | |
throwable.setStackTrace(null) | |
- } | |
- | |
- assertThrows[java.lang.NullPointerException] { | |
- val throwable = new Throwable() | |
- val newStackTrace = Array( | |
- new StackTraceElement("Zero", "noMethod", "noFile", 0), | |
- new StackTraceElement("One", "noMethod", "noFile", 1), | |
- null.asInstanceOf[StackTraceElement], | |
- new StackTraceElement("Three", "noMethod", "noFile", 3) | |
- ) | |
- | |
- throwable.setStackTrace(newStackTrace) | |
- } | |
+ }) | |
+ | |
+ assertThrows( | |
+ classOf[java.lang.NullPointerException], { | |
+ val throwable = new Throwable() | |
+ val newStackTrace = Array( | |
+ new StackTraceElement("Zero", "noMethod", "noFile", 0), | |
+ new StackTraceElement("One", "noMethod", "noFile", 1), | |
+ null.asInstanceOf[StackTraceElement], | |
+ new StackTraceElement("Three", "noMethod", "noFile", 3) | |
+ ) | |
+ | |
+ throwable.setStackTrace(newStackTrace) | |
+ } | |
+ ) | |
} | |
- test("setStackTrace(stackTrace) - writable == true") { | |
+ @Test def setStackTraceStackTraceWritableTrue(): Unit = { | |
val throwable = new Throwable(null, null, true, true) | |
val newStackTrace = Array( | |
@@ -268,14 +273,14 @@ object ThrowablesSuite extends tests.Suite { | |
val afterStackTrace = throwable.getStackTrace() | |
- assert(!afterStackTrace.sameElements(beforeStackTrace), | |
- s"elements after setStackTrace() did not change") | |
+ assertFalse(s"elements after setStackTrace() did not change", | |
+ afterStackTrace.sameElements(beforeStackTrace)) | |
- assert(afterStackTrace.sameElements(newStackTrace), | |
- s"elements after setsetStackTrace() are not as expected") | |
+ assertTrue(s"elements after setsetStackTrace() are not as expected", | |
+ afterStackTrace.sameElements(newStackTrace)) | |
} | |
- test("setStackTrace(stackTrace) - writable == false") { | |
+ @Test def setStackTraceStackTraceWritableFalse(): Unit = { | |
val throwable = new Throwable(null, null, true, false) | |
val newStackTrace = Array( | |
@@ -291,11 +296,11 @@ object ThrowablesSuite extends tests.Suite { | |
val afterStackTrace = throwable.getStackTrace() | |
- assert(afterStackTrace.sameElements(beforeStackTrace), | |
- s"stackTrace elements of non-writable stack differ") | |
+ assertTrue(s"stackTrace elements of non-writable stack differ", | |
+ afterStackTrace.sameElements(beforeStackTrace)) | |
} | |
- test("setStackTrace(stackTrace) - write to returned stack") { | |
+ @Test def setStackTraceStackTraceWriteToReturnedStack(): Unit = { | |
val throwable = new Throwable() | |
val trace1 = throwable.getStackTrace() | |
@@ -304,14 +309,15 @@ object ThrowablesSuite extends tests.Suite { | |
val trace2 = throwable.getStackTrace() | |
- assert(trace2(0) == savedElement0, | |
- s"writing into returned trace should not affect next getStackTrace") | |
+ assertTrue( | |
+ s"writing into returned trace should not affect next getStackTrace", | |
+ trace2(0) == savedElement0) | |
- assert(trace1(0) == null, | |
- s"second getStackTrace() should not change first result") | |
+ assertTrue(s"second getStackTrace() should not change first result", | |
+ trace1(0) == null) | |
} | |
- test("toString()") { | |
+ @Test def testToString(): Unit = { | |
val expectedClassName = "java.lang.Throwable" | |
locally { | |
@@ -319,7 +325,8 @@ object ThrowablesSuite extends tests.Suite { | |
val expected = expectedClassName | |
val result = throwable.toString | |
- assert(result == expected, s"result: ${result} != expected: ${expected}") | |
+ assertTrue(s"result: ${result} != expected: ${expected}", | |
+ result == expected) | |
} | |
locally { | |
@@ -328,7 +335,8 @@ object ThrowablesSuite extends tests.Suite { | |
val expected = s"${expectedClassName}: ${message}" | |
val result = throwable.toString | |
- assert(result == expected, s"result: ${result} != expected: ${expected}") | |
+ assertTrue(s"result: ${result} != expected: ${expected}", | |
+ result == expected) | |
} | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/FloatSuite.scala b/unit-tests/src/test/scala/java/lang/FloatTest.scala | |
index 1e67ddbe..9fa49396 100644 | |
--- a/unit-tests/src/test/scala/java/lang/FloatSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/FloatTest.scala | |
@@ -2,236 +2,244 @@ package java.lang | |
import java.lang.Float.{floatToIntBits, floatToRawIntBits, intBitsToFloat} | |
-object FloatSuite extends tests.Suite { | |
- test("equals") { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class FloatTest { | |
+ @Test def testEquals(): Unit = { | |
val pzero = +0.0f | |
val nzero = -0.0f | |
- assert(pzero equals pzero) | |
- assert(nzero equals nzero) | |
- assertNot(pzero equals nzero) | |
+ assertTrue(pzero equals pzero) | |
+ assertTrue(nzero equals nzero) | |
+ assertFalse(pzero equals nzero) | |
val szero = 1.0f - 1.0f | |
- assert(pzero equals szero) | |
+ assertTrue(pzero equals szero) | |
val bpzero: java.lang.Float = pzero | |
val bnzero: java.lang.Float = nzero | |
- assertNot(bpzero equals bnzero) | |
+ assertFalse(bpzero equals bnzero) | |
val bszero: java.lang.Float = szero | |
- assert(bpzero equals bszero) | |
+ assertTrue(bpzero equals bszero) | |
val num1 = 123.45f | |
val num2 = 123.45f | |
- assert(num1 equals num2) | |
+ assertTrue(num1 equals num2) | |
val bnum1: java.lang.Float = num1 | |
val bnum2: java.lang.Float = num2 | |
- assert(bnum1 == bnum2) | |
+ assertTrue(bnum1 == bnum2) | |
val pmax1 = scala.Float.MaxValue | |
val pmax2 = scala.Float.MaxValue | |
- assert(pmax1 equals pmax2) | |
+ assertTrue(pmax1 equals pmax2) | |
val pmax3 = scala.Float.MaxValue + 1 | |
- assert(pmax1 equals pmax3) | |
+ assertTrue(pmax1 equals pmax3) | |
val bpmax1: java.lang.Float = scala.Float.MaxValue | |
val bpmax2: java.lang.Float = scala.Float.MaxValue | |
- assert(bpmax1 equals bpmax2) | |
+ assertTrue(bpmax1 equals bpmax2) | |
val bpmax3: java.lang.Float = scala.Float.MaxValue + 1 | |
- assert(bpmax1 equals bpmax3) | |
+ assertTrue(bpmax1 equals bpmax3) | |
val pmin1 = scala.Float.MinValue | |
val pmin2 = scala.Float.MinValue | |
- assert(pmin1 equals pmin2) | |
+ assertTrue(pmin1 equals pmin2) | |
val pmin3 = scala.Float.MinValue + 1 | |
- assert(pmin1 equals pmin3) | |
+ assertTrue(pmin1 equals pmin3) | |
val bpmin1: java.lang.Float = scala.Float.MinValue | |
val bpmin2: java.lang.Float = scala.Float.MinValue | |
- assert(bpmin1 equals bpmin2) | |
+ assertTrue(bpmin1 equals bpmin2) | |
val bpmin3: java.lang.Float = scala.Float.MinValue + 1 | |
- assert(bpmin1 equals bpmin3) | |
+ assertTrue(bpmin1 equals bpmin3) | |
val pinf1 = scala.Float.PositiveInfinity | |
val pinf2 = scala.Float.MaxValue + scala.Float.MaxValue | |
- assert(pinf1 equals pinf2) | |
+ assertTrue(pinf1 equals pinf2) | |
val bpinf1: java.lang.Float = pinf1 | |
val bpinf2: java.lang.Float = pinf2 | |
- assert(bpinf1 equals bpinf2) | |
+ assertTrue(bpinf1 equals bpinf2) | |
val ninf1 = scala.Float.NegativeInfinity | |
val ninf2 = scala.Float.MinValue + scala.Float.MinValue | |
- assert(ninf1 equals ninf2) | |
+ assertTrue(ninf1 equals ninf2) | |
val bninf1: java.lang.Float = ninf1 | |
val bninf2: java.lang.Float = ninf2 | |
- assert(bninf1 equals bninf2) | |
+ assertTrue(bninf1 equals bninf2) | |
- assert(Float.NaN equals Float.NaN) | |
+ assertTrue(Float.NaN equals Float.NaN) | |
val x = Float.NaN | |
val y = intBitsToFloat(floatToRawIntBits(x) | 1) | |
- assert(x equals y) | |
+ assertTrue(x equals y) | |
val z = intBitsToFloat(floatToIntBits(x) | 1) | |
- assert(x equals z) | |
+ assertTrue(x equals z) | |
} | |
- test("==") { | |
+ @Test def testEqualEqual(): Unit = { | |
val pzero = +0.0f | |
val nzero = -0.0f | |
- assert(pzero == pzero) | |
- assert(nzero == nzero) | |
- assert(pzero == nzero) | |
+ assertTrue(pzero == pzero) | |
+ assertTrue(nzero == nzero) | |
+ assertTrue(pzero == nzero) | |
val szero = 1.0f - 1.0f | |
- assert(pzero == szero) | |
+ assertTrue(pzero == szero) | |
val bpzero: Any = pzero | |
val bnzero: Any = nzero | |
- assert(bpzero == bnzero) | |
+ assertTrue(bpzero == bnzero) | |
val bszero: java.lang.Float = szero | |
- assert(bpzero == bszero) | |
+ assertTrue(bpzero == bszero) | |
val num1 = 123.45f | |
val num2 = 123.45f | |
- assert(num1 == num2) | |
+ assertTrue(num1 == num2) | |
val bnum1: java.lang.Float = num1 | |
val bnum2: java.lang.Float = num2 | |
- assert(bnum1 == bnum2) | |
+ assertTrue(bnum1 == bnum2) | |
val pmax1 = scala.Float.MaxValue | |
val pmax2 = scala.Float.MaxValue | |
- assert(pmax1 == pmax2) | |
+ assertTrue(pmax1 == pmax2) | |
val pmax3 = scala.Float.MaxValue + 1 | |
- assert(pmax1 == pmax3) | |
+ assertTrue(pmax1 == pmax3) | |
val bpmax1: java.lang.Float = scala.Float.MaxValue | |
val bpmax2: java.lang.Float = scala.Float.MaxValue | |
- assert(bpmax1 == bpmax2) | |
+ assertTrue(bpmax1 == bpmax2) | |
val bpmax3: java.lang.Float = scala.Float.MaxValue + 1 | |
- assert(bpmax1 == bpmax3) | |
+ assertTrue(bpmax1 == bpmax3) | |
val pmin1 = scala.Float.MinValue | |
val pmin2 = scala.Float.MinValue | |
- assert(pmin1 == pmin2) | |
+ assertTrue(pmin1 == pmin2) | |
val pmin3 = scala.Float.MinValue + 1 | |
- assert(pmin1 == pmin3) | |
+ assertTrue(pmin1 == pmin3) | |
val bpmin1: java.lang.Float = scala.Float.MinValue | |
val bpmin2: java.lang.Float = scala.Float.MinValue | |
- assert(bpmin1 == bpmin2) | |
+ assertTrue(bpmin1 == bpmin2) | |
val bpmin3: java.lang.Float = scala.Float.MinValue + 1 | |
- assert(bpmin1 == bpmin3) | |
+ assertTrue(bpmin1 == bpmin3) | |
val pinf1 = scala.Float.PositiveInfinity | |
val pinf2 = scala.Float.MaxValue + scala.Float.MaxValue | |
- assert(pinf1 == pinf2) | |
+ assertTrue(pinf1 == pinf2) | |
val bpinf1: java.lang.Float = pinf1 | |
val bpinf2: java.lang.Float = pinf2 | |
- assert(bpinf1 == bpinf2) | |
+ assertTrue(bpinf1 == bpinf2) | |
val ninf1 = scala.Float.NegativeInfinity | |
val ninf2 = scala.Float.MinValue + scala.Float.MinValue | |
- assert(ninf1 == ninf2) | |
+ assertTrue(ninf1 == ninf2) | |
val bninf1: java.lang.Float = ninf1 | |
val bninf2: java.lang.Float = ninf2 | |
- assert(bninf1 == bninf2) | |
+ assertTrue(bninf1 == bninf2) | |
- assertNot(Float.NaN == Float.NaN) | |
+ assertFalse(Float.NaN == Float.NaN) | |
val x = Float.NaN | |
val y = intBitsToFloat(floatToRawIntBits(x) | 1) | |
- assertNot(x == y) | |
+ assertFalse(x == y) | |
val z = intBitsToFloat(floatToIntBits(x) | 1) | |
- assertNot(x == z) | |
+ assertFalse(x == z) | |
} | |
- test("eq") { | |
+ @Test def testEq(): Unit = { | |
val bpzero: java.lang.Float = +0.0f | |
val bnzero: java.lang.Float = -0.0f | |
- assert(bpzero eq bpzero) | |
- assert(bnzero eq bnzero) | |
- assertNot(bpzero eq bnzero) | |
+ assertTrue(bpzero eq bpzero) | |
+ assertTrue(bnzero eq bnzero) | |
+ assertFalse(bpzero eq bnzero) | |
val bszero: java.lang.Float = 1.0f - 1.0f | |
- assertNot(bpzero eq bszero) | |
+ assertFalse(bpzero eq bszero) | |
val bnum1: java.lang.Float = 123.45f | |
val bnum2: java.lang.Float = 123.45f | |
- assertNot(bnum1 eq bnum2) | |
+ assertFalse(bnum1 eq bnum2) | |
val bpmax1: java.lang.Float = scala.Float.MaxValue | |
val bpmax2: java.lang.Float = scala.Float.MaxValue | |
- assertNot(bpmax1 eq bpmax2) | |
+ assertFalse(bpmax1 eq bpmax2) | |
val bpmax3: java.lang.Float = scala.Float.MaxValue + 1 | |
- assertNot(bpmax1 eq bpmax3) | |
+ assertFalse(bpmax1 eq bpmax3) | |
val bpmin1: java.lang.Float = scala.Float.MinValue | |
val bpmin2: java.lang.Float = scala.Float.MinValue | |
- assertNot(bpmin1 eq bpmin2) | |
+ assertFalse(bpmin1 eq bpmin2) | |
val bpmin3: java.lang.Float = scala.Float.MinValue + 1 | |
- assertNot(bpmin1 eq bpmin3) | |
+ assertFalse(bpmin1 eq bpmin3) | |
val bpinf1: java.lang.Float = scala.Float.PositiveInfinity | |
val bpinf2: java.lang.Float = scala.Float.MaxValue + scala.Float.MaxValue | |
- assertNot(bpinf1 eq bpinf2) | |
+ assertFalse(bpinf1 eq bpinf2) | |
val bninf1: java.lang.Float = scala.Float.NegativeInfinity | |
val bninf2: java.lang.Float = scala.Float.MinValue + scala.Float.MinValue | |
- assertNot(bninf1 eq bninf2) | |
+ assertFalse(bninf1 eq bninf2) | |
} | |
- test("parseFloat") { | |
- assert(Float.parseFloat("1.0") == 1.0f) | |
- assert(Float.parseFloat("-1.0") == -1.0f) | |
- assert(Float.parseFloat("0.0") == 0.0f) | |
- assert(Float.parseFloat("-0.0") == -0.0f) | |
- assert(Float.parseFloat("Infinity") == Float.POSITIVE_INFINITY) | |
- assert(Float.parseFloat("-Infinity") == Float.NEGATIVE_INFINITY) | |
- assert(Float.isNaN(Float.parseFloat("NaN"))) | |
+ @Test def parseFloat(): Unit = { | |
+ assertTrue(Float.parseFloat("1.0") == 1.0f) | |
+ assertTrue(Float.parseFloat("-1.0") == -1.0f) | |
+ assertTrue(Float.parseFloat("0.0") == 0.0f) | |
+ assertTrue(Float.parseFloat("-0.0") == -0.0f) | |
+ assertTrue(Float.parseFloat("Infinity") == Float.POSITIVE_INFINITY) | |
+ assertTrue(Float.parseFloat("-Infinity") == Float.NEGATIVE_INFINITY) | |
+ assertTrue(Float.isNaN(Float.parseFloat("NaN"))) | |
- assert(Float.parseFloat("6.66D") == 6.66f, "a8") | |
+ assertTrue("a8", Float.parseFloat("6.66D") == 6.66f) | |
// Java allows trailing whitespace, including tabs & nulls. | |
- assert(Float.parseFloat("6.66D\t ") == 6.66f, "a9") | |
- assert(Float.parseFloat("6.66D\u0000") == 6.66f, "a9a") | |
+ assertTrue("a9", Float.parseFloat("6.66D\t ") == 6.66f) | |
+ assertTrue("a9a", Float.parseFloat("6.66D\u0000") == 6.66f) | |
- assert(Float.parseFloat("6.66d") == 6.66f, "a10") | |
+ assertTrue("a10", Float.parseFloat("6.66d") == 6.66f) | |
- assert(Float.parseFloat("7.77F") == 7.77f, "a11") | |
- assert(Float.parseFloat("7.77f") == 7.77f, "a12") | |
+ assertTrue("a11", Float.parseFloat("7.77F") == 7.77f) | |
+ assertTrue("a12", Float.parseFloat("7.77f") == 7.77f) | |
// Does not parse characters beyond IEEE754 spec. | |
- assert( | |
- Float.parseFloat("1.7976931348623157999999999") == 1.7976931348623157f, | |
- "a13") | |
- | |
- assertThrows[NumberFormatException](Float.parseFloat("")) | |
- assertThrows[NumberFormatException](Float.parseFloat("F")) | |
- assertThrows[NumberFormatException](Float.parseFloat("potato")) | |
- assertThrows[NumberFormatException](Float.parseFloat("0.0potato")) | |
- assertThrows[NumberFormatException](Float.parseFloat("0.potato")) | |
- | |
- assertThrows[NumberFormatException](Float.parseFloat("6.66 F")) | |
- assertThrows[NumberFormatException](Float.parseFloat("6.66F Bad ")) | |
- assertThrows[NumberFormatException](Float.parseFloat("6.66F\u0000a")) | |
- assertThrows[NumberFormatException](Float.parseFloat("6.66F \u0100")) | |
+ assertTrue( | |
+ "a13", | |
+ Float.parseFloat("1.7976931348623157999999999") == 1.7976931348623157f) | |
+ | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("")) | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("F")) | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("potato")) | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("0.0potato")) | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("0.potato")) | |
+ | |
+ assertThrows(classOf[NumberFormatException], Float.parseFloat("6.66 F")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Float.parseFloat("6.66F Bad ")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Float.parseFloat("6.66F\u0000a")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ Float.parseFloat("6.66F \u0100")) | |
// Out of IEE754 range handling | |
// Too big - java.lang.Float.MAX_VALUE times 10 | |
- assert(Float.parseFloat("3.4028235E39") == | |
- Float.POSITIVE_INFINITY, | |
- "a20") | |
+ assertTrue("a20", | |
+ Float.parseFloat("3.4028235E39") == | |
+ Float.POSITIVE_INFINITY) | |
// Too big - Negative java.lang.Float.MAX_VALUE times 10 | |
- assert(Float.parseFloat("-3.4028235E39") == | |
- Float.NEGATIVE_INFINITY, | |
- "a21") | |
+ assertTrue("a21", | |
+ Float.parseFloat("-3.4028235E39") == | |
+ Float.NEGATIVE_INFINITY) | |
// Too close to 0 - java.lang.Float.MIN_VALUE divided by 10 | |
- assert(Float.parseFloat("1.4E-46") == 0.0f, "a22") | |
+ assertTrue("a22", Float.parseFloat("1.4E-46") == 0.0f) | |
// Scala Native Issue #1836, a string Too Big reported from the wild. | |
val a = "274672389457236457826542634627345697228374687236476867674746" + | |
@@ -240,24 +248,24 @@ object FloatSuite extends tests.Suite { | |
"7384567845678658734587364576745683475674576345786348576847567846578" + | |
"3456702897830296720476846578634576384567845678346573465786457863" | |
- assert(Float.parseFloat(a) == Float.POSITIVE_INFINITY, "a23") | |
+ assertTrue("a23", Float.parseFloat(a) == Float.POSITIVE_INFINITY) | |
// Hexadecimal strings | |
- assert(Float.parseFloat("0x0p1") == 0.0f, "a30") | |
- assert(Float.parseFloat("0x1p0") == 1.0f, "a31") | |
- assert(Float.parseFloat("0x1p1D") == 2.0f, "a32") | |
+ assertTrue("a30", Float.parseFloat("0x0p1") == 0.0f) | |
+ assertTrue("a31", Float.parseFloat("0x1p0") == 1.0f) | |
+ assertTrue("a32", Float.parseFloat("0x1p1D") == 2.0f) | |
- assert(Float.parseFloat("0x1.8eae14p6") == 99.67f, "a33") | |
- assert(Float.parseFloat("-0x1.8eae14p6") == -99.67f, "a34") | |
+ assertTrue("a33", Float.parseFloat("0x1.8eae14p6") == 99.67f) | |
+ assertTrue("a34", Float.parseFloat("-0x1.8eae14p6") == -99.67f) | |
} | |
// scala.Float passes -0.0F without change. j.l.Double forced to +0.0. | |
private def assertF2sEquals(expected: String, f: scala.Float): Unit = { | |
val result = f.toString | |
- assert(expected == result, s"result: $result != expected: $expected") | |
+ assertTrue(s"result: $result != expected: $expected", expected == result) | |
} | |
- test("toString") { | |
+ @Test def testToString(): Unit = { | |
// Test non-finite values. | |
assertF2sEquals("Infinity", Float.POSITIVE_INFINITY) | |
diff --git a/unit-tests/src/test/scala/java/lang/ScalaNumberSuite.scala b/unit-tests/src/test/scala/java/lang/ScalaNumberTest.scala | |
index df185f64..a4065230 100644 | |
--- a/unit-tests/src/test/scala/java/lang/ScalaNumberSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/ScalaNumberTest.scala | |
@@ -2,28 +2,28 @@ package java.lang | |
// Exercise __scala_== | |
-object ScalaNumberSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
- test("BigInt") { // Section header, visually group tests | |
- } | |
+class ScalaNumberTest { | |
- test(" BigInt == BigInt") { | |
+ @Test def bigIntEqualEqualBigInt(): Unit = { | |
val token = 2047L | |
val sbi1: scala.math.BigInt = scala.math.BigInt(token) | |
val sbi2: scala.math.BigInt = scala.math.BigInt(token) | |
- assert(sbi1 == sbi2) | |
+ assertTrue(sbi1 == sbi2) | |
} | |
- test(" BigInt.equals(BigInt)") { | |
+ @Test def bigIntEqualsBigInt(): Unit = { | |
val token = 2047L | |
val sbi1: scala.math.BigInt = scala.math.BigInt(token) | |
val sbi2: scala.math.BigInt = scala.math.BigInt(token) | |
- assert(sbi1.equals(sbi2)) | |
+ assertTrue(sbi1.equals(sbi2)) | |
} | |
- test(" BigInt does not == BigInt with different value") { | |
+ @Test def bigIntDoesNotEqualEqualBigIntWithDifferentValue(): Unit = { | |
val token = 2047L | |
val sbi1: scala.math.BigInt = scala.math.BigInt(token) | |
// avoid powers of 2 because of possible caching. | |
@@ -32,15 +32,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbi1 == sbi2) | |
} | |
- test(" BigInt == j.l.Long") { | |
+ @Test def bigIntEqualEqualJavaLong(): Unit = { | |
val token = Int.MaxValue + 2L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val jl: java.lang.Long = new java.lang.Long(token.toString) | |
- assert(sbi == jl) | |
+ assertTrue(sbi == jl) | |
} | |
- test(" BigInt does not == j.l.Long with different value") { | |
+ @Test def bigIntDoesNotEqualEqualJavaLongWithDifferentValue(): Unit = { | |
val token = Int.MaxValue + 2L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val jl: java.lang.Long = new java.lang.Long((token + 2).toString) | |
@@ -48,15 +48,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbi == jl) | |
} | |
- test(" j.l.Long == BigInt") { | |
+ @Test def javaLongEqualEqualBigInt(): Unit = { | |
val token = Int.MaxValue + 2L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val jl: java.lang.Long = new java.lang.Long(token.toString) | |
- assert(jl == sbi) | |
+ assertTrue(jl == sbi) | |
} | |
- test(" j.l.Long does not == BigInt with different value") { | |
+ @Test def javaLongDoesNotEqualEqualBigIntWithDifferentValue(): Unit = { | |
val token = Int.MaxValue + 2L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val jl: java.lang.Long = new java.lang.Long((token + 2).toString) | |
@@ -64,15 +64,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(jl == sbi) | |
} | |
- test(" j.l.Long == j.l.Long") { | |
+ @Test def javaLongEqualEqualJavaLong(): Unit = { | |
val token = 2047 | |
val jl1: java.lang.Long = new java.lang.Long(token) | |
val jl2: java.lang.Long = new java.lang.Long(token) | |
- assert(jl1 == jl2) | |
+ assertTrue(jl1 == jl2) | |
} | |
- test(" j.l.Long does not == j.l.Long with different value") { | |
+ @Test def javaLongDoesNotEqualEqualJavaLongWithDifferentValue(): Unit = { | |
val token = 2047 | |
val jl1: java.lang.Long = new java.lang.Long(token) | |
val jl2: java.lang.Long = new java.lang.Long(token + 2) | |
@@ -80,15 +80,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(jl1 == jl2) | |
} | |
- test(" BigInt == j.l.Integer") { | |
+ @Test def bigIntEqualEqualJavaInteger(): Unit = { | |
val token = 2047L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val ji: java.lang.Integer = new java.lang.Integer(token.toString) | |
- assert(sbi == ji) | |
+ assertTrue(sbi == ji) | |
} | |
- test(" BigInt does not == j.l.Integer with different value") { | |
+ @Test def bigIntDoesNotEqualEqualJavaIntegerWithDifferentValue(): Unit = { | |
val token = 2047L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val ji: java.lang.Integer = new java.lang.Integer((token + 2).toString) | |
@@ -96,15 +96,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbi == ji) | |
} | |
- test(" j.l.Integer == BigInt") { | |
+ @Test def javaIntegerEqualEqualBigInt(): Unit = { | |
val token = 2047L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val ji: java.lang.Integer = new java.lang.Integer(token.toString) | |
- assert(ji == sbi) | |
+ assertTrue(ji == sbi) | |
} | |
- test(" j.l.Integer does not == BigInt with different value") { | |
+ @Test def javaIntegerDoesNotEqualEqualBigIntWithDifferentValue(): Unit = { | |
val token = 2047L | |
val sbi: scala.math.BigInt = scala.math.BigInt(token) | |
val ji: java.lang.Integer = new java.lang.Integer((token + 2).toString) | |
@@ -112,15 +112,16 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(ji == sbi) | |
} | |
- test(" j.l.Integer == j.l.Integer") { | |
+ @Test def javaIntegerEqualEqualJavaInteger(): Unit = { | |
val token = 2047 | |
val ji1: java.lang.Integer = new java.lang.Integer(token) | |
val ji2: java.lang.Integer = new java.lang.Integer(token) | |
- assert(ji1 == ji2) | |
+ assertTrue(ji1 == ji2) | |
} | |
- test(" j.l.Integer does not == j.l.Integer with different value") { | |
+ @Test def javaIntegerDoesNotEqualEqualJavaIntegerWithDifferentValue() | |
+ : Unit = { | |
val token = 2047 | |
val ji1: java.lang.Integer = new java.lang.Integer(token) | |
val ji2: java.lang.Integer = new java.lang.Integer(token + 2) | |
@@ -128,26 +129,23 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(ji1 == ji2) | |
} | |
- test("BigDecimal") { // Section header, visually group tests | |
- } | |
- | |
- test(" BigDecimal == BigDecimal") { | |
+ @Test def bigDecimalEqualEqualBigDecimal(): Unit = { | |
val token = 2046.5 | |
val sbd1: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val sbd2: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
- assert(sbd1 == sbd2) | |
+ assertTrue(sbd1 == sbd2) | |
} | |
- test(" BigDecimal.equals(BigDecimal)") { | |
+ @Test def bigDecimalEqualsBigDecimal(): Unit = { | |
val token = 2046.5 | |
val sbd1: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val sbd2: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
- assert(sbd1.equals(sbd2)) | |
+ assertTrue(sbd1.equals(sbd2)) | |
} | |
- test(" BigDecimal does not == BigDecimal with different value") { | |
+ @Test def bigDecimalDoesNotEqualEqualBigDecimalWithDifferentValue(): Unit = { | |
val token = 2046.5 | |
val sbd1: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val sbd2: scala.math.BigDecimal = scala.math.BigDecimal(token - 2.0) | |
@@ -155,15 +153,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbd1 == sbd2) | |
} | |
- test(" BigDecimal == j.l.Double") { | |
+ @Test def bigDecimalEqualEqualJavaDouble(): Unit = { | |
val token = 2046.5 | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jd: java.lang.Double = new java.lang.Double(token.toString) | |
- assert(sbd == jd) | |
+ assertTrue(sbd == jd) | |
} | |
- test(" BigDecimal does not == j.l.Double with different value") { | |
+ @Test def bigDecimalDoesNotEqualEqualJavaDoubleWithDifferentValue(): Unit = { | |
val token = 2046.5 | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jd: java.lang.Double = new java.lang.Double((token - 2.0).toString) | |
@@ -171,15 +169,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbd == jd) | |
} | |
- test(" j.l.Double == BigDecimal") { | |
+ @Test def javaDoubleEqualEqualBigDecimal(): Unit = { | |
val token = 2046.5 | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jd: java.lang.Double = new java.lang.Double(token.toString) | |
- assert(jd == sbd) | |
+ assertTrue(jd == sbd) | |
} | |
- test(" j.l.Double does not == BigDecimal with different value") { | |
+ @Test def javaDoubleDoesNotEqualEqualBigDecimalWithDifferentValue(): Unit = { | |
val token = 2046.5 | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jd: java.lang.Double = new java.lang.Double((token - 2.0).toString) | |
@@ -187,15 +185,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbd == jd) | |
} | |
- test(" j.l.Double == j.l.Double") { | |
+ @Test def javaDoubleEqualEqualJavaDouble(): Unit = { | |
val token = 2046.5 | |
val jd1: java.lang.Double = new java.lang.Double(token) | |
val jd2: java.lang.Double = new java.lang.Double(token) | |
- assert(jd1 == jd2) | |
+ assertTrue(jd1 == jd2) | |
} | |
- test(" j.l.Double does not == j.l.Double with different value") { | |
+ @Test def javaDoubleDoesNotEqualEqualJavaDoubleWithDifferentValue(): Unit = { | |
val token = 2046.5 | |
val jd1: java.lang.Double = new java.lang.Double(token) | |
val jd2: java.lang.Double = new java.lang.Double((token - 2.0).toString) | |
@@ -203,15 +201,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(jd1 == jd2) | |
} | |
- test(" BigDecimal == j.l.Float") { | |
+ @Test def bigDecimalEqualEqualJavaFloat(): Unit = { | |
val token = 2046.5F | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jf: java.lang.Float = new java.lang.Float(token.toString) | |
- assert(sbd == jf) | |
+ assertTrue(sbd == jf) | |
} | |
- test(" BigDecimal does not == j.l.Float with different value") { | |
+ @Test def bigDecimalDoesNotEqualEqualJavaFloatWithDifferentValue(): Unit = { | |
val token = 2046.5F | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jf: java.lang.Float = new java.lang.Float((token - 2.0).toString) | |
@@ -219,15 +217,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(sbd == jf) | |
} | |
- test(" j.l.Float == BigDecimal") { | |
+ @Test def javaFloatEqualEqualBigDecimal(): Unit = { | |
val token = 2046.5F | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jf: java.lang.Float = new java.lang.Float(token.toString) | |
- assert(jf == sbd) | |
+ assertTrue(jf == sbd) | |
} | |
- test(" j.l.Float does not == BigDecimal with different value") { | |
+ @Test def javaFloatDoesNotEqualEqualBigDecimalWithDifferentValue(): Unit = { | |
val token = 2046.5F | |
val sbd: scala.math.BigDecimal = scala.math.BigDecimal(token) | |
val jf: java.lang.Float = new java.lang.Float((token - 2.0).toString) | |
@@ -235,15 +233,15 @@ object ScalaNumberSuite extends tests.Suite { | |
assertFalse(jf == sbd) | |
} | |
- test(" j.l.Float == j.l.Float") { | |
+ @Test def javaFloatEqualEqualJavaFloat(): Unit = { | |
val token = 2046.5F | |
val jf1: java.lang.Float = new java.lang.Float(token) | |
val jf2: java.lang.Float = new java.lang.Float(token) | |
- assert(jf1 == jf2) | |
+ assertTrue(jf1 == jf2) | |
} | |
- test(" j.l.Float does not == j.l.Float with different value") { | |
+ @Test def javaFloatDoesNotEqualEqualJavaFloatWithDifferentValue(): Unit = { | |
val token = 2046.5F | |
val jf1: java.lang.Float = new java.lang.Float(token) | |
val jf2: java.lang.Float = new java.lang.Float((token - 2.0).toString) | |
diff --git a/unit-tests/src/test/scala/java/lang/ExceptionSuite.scala b/unit-tests/src/test/scala/java/lang/ExceptionTest.scala | |
index 4159b176..26d5c946 100644 | |
--- a/unit-tests/src/test/scala/java/lang/ExceptionSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/ExceptionTest.scala | |
@@ -1,18 +1,21 @@ | |
package java.lang | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
class DummyNoStackTraceException extends scala.util.control.NoStackTrace | |
-object ExceptionSuite extends tests.Suite { | |
- test("printStackTrace") { | |
+class ExceptionTest { | |
+ @Test def printStackTrace(): Unit = { | |
val sw = new java.io.StringWriter | |
val pw = new java.io.PrintWriter(sw) | |
(new Exception).printStackTrace(pw) | |
val trace = sw.toString | |
- assert(trace.startsWith("java.lang.Exception")) | |
- assert(trace.contains("\tat <none>.main(Unknown Source)")) | |
+ assertTrue(trace.startsWith("java.lang.Exception")) | |
+ assertTrue(trace.contains("\tat <none>.main(Unknown Source)")) | |
} | |
- test("printStackTrace <no stack trace available>") { | |
+ @Test def printStackTraceNoStackTraceAvailable(): Unit = { | |
val sw = new java.io.StringWriter | |
val pw = new java.io.PrintWriter(sw) | |
(new DummyNoStackTraceException).printStackTrace(pw) | |
@@ -21,6 +24,6 @@ object ExceptionSuite extends tests.Suite { | |
"java.lang.DummyNoStackTraceException", | |
"\t<no stack trace available>" | |
).mkString("\n") | |
- assert(trace.startsWith(expected)) | |
+ assertTrue(trace.startsWith(expected)) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/LongSuite.scala b/unit-tests/src/test/scala/java/lang/LongTest.scala | |
index d09f0793..40c67b5e 100644 | |
--- a/unit-tests/src/test/scala/java/lang/LongSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/LongTest.scala | |
@@ -1,6 +1,11 @@ | |
package java.lang | |
-object LongSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class LongTest { | |
val signedMaxValue = Long.MAX_VALUE | |
val signedMaxValueText = "9223372036854775807" | |
val signedMinValue = Long.MIN_VALUE | |
@@ -13,127 +18,131 @@ object LongSuite extends tests.Suite { | |
val unsignedMaxValueText = "18446744073709551615" | |
val unsignedMaxPlusOneText = "18446744073709551616" | |
- test("parseLong") { | |
+ @Test def parseLong(): Unit = { | |
import Long.{parseLong => parse} | |
- assert(parse("-1") == -1L) | |
- assert(parse("+1") == 1L) | |
- assert(parse("1") == 1L) | |
- assert(parse("-123") == -123L) | |
- assert(parse("+123") == 123L) | |
- assert(parse("123") == 123L) | |
- assert(parse("-100", 2) == -4L) | |
- assert(parse("+100", 2) == 4L) | |
- assert(parse("100", 2) == 4L) | |
- assert(parse("-0") == 0L) | |
- assert(parse("+0") == 0L) | |
- assert(parse("00") == 0L) | |
- assert(parse(signedMaxValueText) == signedMaxValue) | |
- assert(parse(signedMinValueText) == signedMinValue) | |
- | |
- assertThrows[NumberFormatException](parse(null)) | |
- assertThrows[NumberFormatException](parse("+")) | |
- assertThrows[NumberFormatException](parse("-")) | |
- assertThrows[NumberFormatException](parse("")) | |
- assertThrows[NumberFormatException](parse("123", Character.MIN_RADIX - 1)) | |
- assertThrows[NumberFormatException](parse("123", Character.MAX_RADIX + 1)) | |
- assertThrows[NumberFormatException](parse("123a", 10)) | |
- assertThrows[NumberFormatException](parse(signedMinMinusOneText)) | |
- assertThrows[NumberFormatException](parse(signedMaxPlusOneText)) | |
+ assertTrue(parse("-1") == -1L) | |
+ assertTrue(parse("+1") == 1L) | |
+ assertTrue(parse("1") == 1L) | |
+ assertTrue(parse("-123") == -123L) | |
+ assertTrue(parse("+123") == 123L) | |
+ assertTrue(parse("123") == 123L) | |
+ assertTrue(parse("-100", 2) == -4L) | |
+ assertTrue(parse("+100", 2) == 4L) | |
+ assertTrue(parse("100", 2) == 4L) | |
+ assertTrue(parse("-0") == 0L) | |
+ assertTrue(parse("+0") == 0L) | |
+ assertTrue(parse("00") == 0L) | |
+ assertTrue(parse(signedMaxValueText) == signedMaxValue) | |
+ assertTrue(parse(signedMinValueText) == signedMinValue) | |
+ | |
+ assertThrows(classOf[NumberFormatException], parse(null)) | |
+ assertThrows(classOf[NumberFormatException], parse("+")) | |
+ assertThrows(classOf[NumberFormatException], parse("-")) | |
+ assertThrows(classOf[NumberFormatException], parse("")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MIN_RADIX - 1)) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MAX_RADIX + 1)) | |
+ assertThrows(classOf[NumberFormatException], parse("123a", 10)) | |
+ assertThrows(classOf[NumberFormatException], parse(signedMinMinusOneText)) | |
+ assertThrows(classOf[NumberFormatException], parse(signedMaxPlusOneText)) | |
} | |
- test("parseUnsignedLong") { | |
+ @Test def parseUnsignedLong(): Unit = { | |
import Long.{parseUnsignedLong => parse} | |
- assert(parse("1") == 1) | |
- assert(parse("+1") == 1) | |
- assert(parse("0") == 0) | |
- assert(parse("00") == 0) | |
- assert(parse("+100", 2) == 4) | |
- assert(parse("100", 2) == 4) | |
- assert(parse(unsignedMaxValueText) == unsignedMaxValue) | |
- | |
- assertThrows[NumberFormatException](parse(null)) | |
- assertThrows[NumberFormatException](parse("+")) | |
- assertThrows[NumberFormatException](parse("-")) | |
- assertThrows[NumberFormatException](parse("")) | |
- assertThrows[NumberFormatException](parse("-1")) | |
- assertThrows[NumberFormatException](parse("123", Character.MIN_RADIX - 1)) | |
- assertThrows[NumberFormatException](parse("123", Character.MAX_RADIX + 1)) | |
- assertThrows[NumberFormatException](parse("123a", 10)) | |
- assertThrows[NumberFormatException](parse(unsignedMaxPlusOneText)) | |
+ assertTrue(parse("1") == 1) | |
+ assertTrue(parse("+1") == 1) | |
+ assertTrue(parse("0") == 0) | |
+ assertTrue(parse("00") == 0) | |
+ assertTrue(parse("+100", 2) == 4) | |
+ assertTrue(parse("100", 2) == 4) | |
+ assertTrue(parse(unsignedMaxValueText) == unsignedMaxValue) | |
+ | |
+ assertThrows(classOf[NumberFormatException], parse(null)) | |
+ assertThrows(classOf[NumberFormatException], parse("+")) | |
+ assertThrows(classOf[NumberFormatException], parse("-")) | |
+ assertThrows(classOf[NumberFormatException], parse("")) | |
+ assertThrows(classOf[NumberFormatException], parse("-1")) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MIN_RADIX - 1)) | |
+ assertThrows(classOf[NumberFormatException], | |
+ parse("123", Character.MAX_RADIX + 1)) | |
+ assertThrows(classOf[NumberFormatException], parse("123a", 10)) | |
+ assertThrows(classOf[NumberFormatException], parse(unsignedMaxPlusOneText)) | |
val octalMulOverflow = "5777777777777777777770" | |
// in binary: | |
// octalMulOverflow: 0101111111111111111111111111111111111111111111111111111111111111000 | |
// max unsigned: 0001111111111111111111111111111111111111111111111111111111111111111 | |
- assertThrows[NumberFormatException](parse(octalMulOverflow, 8)) | |
+ assertThrows(classOf[NumberFormatException], parse(octalMulOverflow, 8)) | |
} | |
- test("toString") { | |
+ @Test def testToString(): Unit = { | |
import java.lang.Long.{toString => toStr} | |
- assert(toStr(0L) == "0") | |
- assert(toStr(1L) == "1") | |
- assert(toStr(12L) == "12") | |
- assert(toStr(123L) == "123") | |
- assert(toStr(1234L) == "1234") | |
- assert(toStr(12345L) == "12345") | |
- assert(toStr(10L) == "10") | |
- assert(toStr(100L) == "100") | |
- assert(toStr(1000L) == "1000") | |
- assert(toStr(10000L) == "10000") | |
- assert(toStr(100000L) == "100000") | |
- assert(toStr(101010L) == "101010") | |
- assert(toStr(111111L) == "111111") | |
- assert(toStr(-1L) == "-1") | |
- assert(toStr(-12L) == "-12") | |
- assert(toStr(-123L) == "-123") | |
- assert(toStr(-1234L) == "-1234") | |
- assert(toStr(-12345L) == "-12345") | |
- assert(toStr(signedMaxValue) == signedMaxValueText) | |
- assert(toStr(signedMinValue) == signedMinValueText) | |
+ assertTrue(toStr(0L) == "0") | |
+ assertTrue(toStr(1L) == "1") | |
+ assertTrue(toStr(12L) == "12") | |
+ assertTrue(toStr(123L) == "123") | |
+ assertTrue(toStr(1234L) == "1234") | |
+ assertTrue(toStr(12345L) == "12345") | |
+ assertTrue(toStr(10L) == "10") | |
+ assertTrue(toStr(100L) == "100") | |
+ assertTrue(toStr(1000L) == "1000") | |
+ assertTrue(toStr(10000L) == "10000") | |
+ assertTrue(toStr(100000L) == "100000") | |
+ assertTrue(toStr(101010L) == "101010") | |
+ assertTrue(toStr(111111L) == "111111") | |
+ assertTrue(toStr(-1L) == "-1") | |
+ assertTrue(toStr(-12L) == "-12") | |
+ assertTrue(toStr(-123L) == "-123") | |
+ assertTrue(toStr(-1234L) == "-1234") | |
+ assertTrue(toStr(-12345L) == "-12345") | |
+ assertTrue(toStr(signedMaxValue) == signedMaxValueText) | |
+ assertTrue(toStr(signedMinValue) == signedMinValueText) | |
} | |
- test("toUnsignedString") { | |
+ @Test def toUnsignedString(): Unit = { | |
import java.lang.Long.{toUnsignedString => toStr} | |
- assert(toStr(0L) == "0") | |
- assert(toStr(1L) == "1") | |
- assert(toStr(12L) == "12") | |
- assert(toStr(123L) == "123") | |
- assert(toStr(1234L) == "1234") | |
- assert(toStr(12345L) == "12345") | |
- assert(toStr(-1L) == "18446744073709551615") | |
- assert(toStr(-12L) == "18446744073709551604") | |
- assert(toStr(-123L) == "18446744073709551493") | |
- assert(toStr(-1234L) == "18446744073709550382") | |
- assert(toStr(-12345L) == "18446744073709539271") | |
- assert(toStr(unsignedMaxValue) == unsignedMaxValueText) | |
+ assertTrue(toStr(0L) == "0") | |
+ assertTrue(toStr(1L) == "1") | |
+ assertTrue(toStr(12L) == "12") | |
+ assertTrue(toStr(123L) == "123") | |
+ assertTrue(toStr(1234L) == "1234") | |
+ assertTrue(toStr(12345L) == "12345") | |
+ assertTrue(toStr(-1L) == "18446744073709551615") | |
+ assertTrue(toStr(-12L) == "18446744073709551604") | |
+ assertTrue(toStr(-123L) == "18446744073709551493") | |
+ assertTrue(toStr(-1234L) == "18446744073709550382") | |
+ assertTrue(toStr(-12345L) == "18446744073709539271") | |
+ assertTrue(toStr(unsignedMaxValue) == unsignedMaxValueText) | |
} | |
- test("equals") { | |
- assert(new Long(0) == new Long(0)) | |
- assert(new Long(1) == new Long(1)) | |
- assert(new Long(-1) == new Long(-1)) | |
- assert(new Long(123) == new Long(123)) | |
- assert(new Long(Long.MAX_VALUE) == new Long(Long.MAX_VALUE)) | |
- assert(new Long(Long.MIN_VALUE) == new Long(Long.MIN_VALUE)) | |
+ @Test def testEquals(): Unit = { | |
+ assertTrue(new Long(0) == new Long(0)) | |
+ assertTrue(new Long(1) == new Long(1)) | |
+ assertTrue(new Long(-1) == new Long(-1)) | |
+ assertTrue(new Long(123) == new Long(123)) | |
+ assertTrue(new Long(Long.MAX_VALUE) == new Long(Long.MAX_VALUE)) | |
+ assertTrue(new Long(Long.MIN_VALUE) == new Long(Long.MIN_VALUE)) | |
} | |
- test("highestOneBit") { | |
- assert(Long.highestOneBit(1) == 1L) | |
- assert(Long.highestOneBit(2) == 2L) | |
- assert(Long.highestOneBit(3) == 2L) | |
- assert(Long.highestOneBit(4) == 4L) | |
- assert(Long.highestOneBit(5) == 4L) | |
- assert(Long.highestOneBit(6) == 4L) | |
- assert(Long.highestOneBit(7) == 4L) | |
- assert(Long.highestOneBit(8) == 8L) | |
- assert(Long.highestOneBit(9) == 8L) | |
- assert(Long.highestOneBit(63) == 32L) | |
- assert(Long.highestOneBit(64) == 64L) | |
- assert(Long.highestOneBit(Int.MaxValue) == 1073741824) | |
- assert(Long.highestOneBit(Int.MaxValue + 1L) == 2147483648L) | |
+ @Test def highestOneBit(): Unit = { | |
+ assertTrue(Long.highestOneBit(1) == 1L) | |
+ assertTrue(Long.highestOneBit(2) == 2L) | |
+ assertTrue(Long.highestOneBit(3) == 2L) | |
+ assertTrue(Long.highestOneBit(4) == 4L) | |
+ assertTrue(Long.highestOneBit(5) == 4L) | |
+ assertTrue(Long.highestOneBit(6) == 4L) | |
+ assertTrue(Long.highestOneBit(7) == 4L) | |
+ assertTrue(Long.highestOneBit(8) == 8L) | |
+ assertTrue(Long.highestOneBit(9) == 8L) | |
+ assertTrue(Long.highestOneBit(63) == 32L) | |
+ assertTrue(Long.highestOneBit(64) == 64L) | |
+ assertTrue(Long.highestOneBit(Int.MaxValue) == 1073741824) | |
+ assertTrue(Long.highestOneBit(Int.MaxValue + 1L) == 2147483648L) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/RuntimeSuite.scala b/unit-tests/src/test/scala/java/lang/RuntimeTest.scala | |
index df6c89d9..3940c05e 100644 | |
--- a/unit-tests/src/test/scala/java/lang/RuntimeSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/RuntimeTest.scala | |
@@ -3,25 +3,28 @@ package java.lang | |
import java.util.concurrent.TimeUnit | |
import java.io.File | |
-object RuntimeSuite extends tests.Suite { | |
- import ProcessSuite._ | |
- test("exec command") { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+class RuntimeTest { | |
+ import ProcessUtils._ | |
+ @Test def execCommand(): Unit = { | |
val proc = Runtime.getRuntime.exec(Array("ls", resourceDir)) | |
val out = readInputStream(proc.getInputStream) | |
- assert(proc.waitFor(5, TimeUnit.SECONDS)) | |
- assert(out.split("\n").toSet == Set("echo.sh", "err.sh", "hello.sh", "ls")) | |
+ assertTrue(proc.waitFor(5, TimeUnit.SECONDS)) | |
+ assertTrue(out.split("\n").toSet == Set("echo.sh", "err.sh", "hello.sh", "ls")) | |
} | |
- test("exec envp") { | |
+ @Test def execEnvp(): Unit = { | |
val envp = Array(s"PATH=$resourceDir") | |
val proc = Runtime.getRuntime.exec(Array("ls"), envp) | |
val out = readInputStream(proc.getInputStream) | |
- assert(proc.waitFor(5, TimeUnit.SECONDS)) | |
- assert(out == "1") | |
+ assertTrue(proc.waitFor(5, TimeUnit.SECONDS)) | |
+ assertTrue(out == "1") | |
} | |
- test("exec dir") { | |
+ @Test def execDir(): Unit = { | |
val proc = Runtime.getRuntime.exec(Array("ls"), null, new File(resourceDir)) | |
val out = readInputStream(proc.getInputStream) | |
- assert(proc.waitFor(5, TimeUnit.SECONDS)) | |
- assert(out.split("\n").toSet == Set("echo.sh", "err.sh", "hello.sh", "ls")) | |
+ assertTrue(proc.waitFor(5, TimeUnit.SECONDS)) | |
+ assertTrue(out.split("\n").toSet == Set("echo.sh", "err.sh", "hello.sh", "ls")) | |
} | |
} | |
diff --git a/unit-tests/src/test/scala/java/lang/StringBufferSuite.scala b/unit-tests/src/test/scala/java/lang/StringBufferTest.scala | |
index a5f4ab50..0f0b5f94 100644 | |
--- a/unit-tests/src/test/scala/java/lang/StringBufferSuite.scala | |
+++ b/unit-tests/src/test/scala/java/lang/StringBufferTest.scala | |
@@ -2,7 +2,12 @@ package java.lang | |
// Ported from Scala.js | |
-object StringBufferSuite extends tests.Suite { | |
+import org.junit.Test | |
+import org.junit.Assert._ | |
+ | |
+import scalanative.junit.utils.AssertThrows._ | |
+ | |
+class StringBufferTest { | |
def newBuf: java.lang.StringBuffer = | |
new java.lang.StringBuffer | |
@@ -10,7 +15,7 @@ object StringBufferSuite extends tests.Suite { | |
def initBuf(str: String): java.lang.StringBuffer = | |
new java.lang.StringBuffer(str) | |
- test("append") { | |
+ @Test def append(): Unit = { | |
assertEquals("asdf", newBuf.append("asdf").toString) | |
assertEquals("null", newBuf.append(null: AnyRef).toString) | |
assertEquals("null", newBuf.append(null: String).toString) | |
@@ -24,12 +29,12 @@ object StringBufferSuite extends tests.Suite { | |
assertEquals("100000", newBuf.append(100000).toString) | |
} | |
- test("append float") { | |
+ @Test def appendFloat(): Unit = { | |
assertEquals("2.5", newBuf.append(2.5f).toString) | |
assertEquals("3.5", newBuf.append(3.5).toString) | |
} | |
- test("insert") { | |
+ @Test def insert(): Unit = { | |
assertEquals("asdf", newBuf.insert(0, "asdf").toString) | |
assertEquals("null", newBuf.insert(0, null: AnyRef).toString) | |
assertEquals("null", newBuf.insert(0, null: String).toString) | |
@@ -57,17 +62,18 @@ object StringBufferSuite extends tests.Suite { | |
initBuf("abcd").insert(5, "whatever")) | |
} | |
- test("insert float") { | |
+ @Test def insertFloat(): Unit = { | |
assertEquals("2.5", newBuf.insert(0, 2.5f).toString) | |
assertEquals("3.5", newBuf.insert(0, 3.5).toString) | |
} | |
// TODO: segfaults with EXC_BAD_ACCESS (code=1, address=0x0) | |
- // testFails("insert string buffer", issue = -1) { | |
- // assertEquals("abcdef", initBuf("abef").insert(2, initBuf("abcde"), 2, 4).toString) | |
- // } | |
+ @Test def insertStringBuffer(): Unit = { | |
+ assertEquals("abcdef", | |
+ initBuf("abef").insert(2, initBuf("abcde"), 2, 4).toString) | |
+ } | |
- test("deleteCharAt") { | |
+ @Test def deleteCharAt(): Unit = { | |
assertEquals("023", initBuf("0123").deleteCharAt(1).toString) | |
assertEquals("123", initBuf("0123").deleteCharAt(0).toString) | |
assertEquals("012", initBuf("0123").deleteCharAt(3).toString) | |
@@ -77,7 +83,7 @@ object StringBufferSuite extends tests.Suite { | |
initBuf("0123").deleteCharAt(4)) | |
} | |
- test("replace") { | |
+ @Test def replace(): Unit = { | |
assertEquals("0bc3", initBuf("0123").replace(1, 3, "bc").toString) | |
assertEquals("abcd", initBuf("0123").replace(0, 4, "abcd").toString) | |
assertEquals("abcd", initBuf("0123").replace(0, 10, "abcd").toString) | |
@@ -90,7 +96,7 @@ object StringBufferSuite extends tests.Suite { | |
initBuf("0123").replace(-1, 3, "x")) | |
} | |
- test("setCharAt") { | |
+ @Test def setCharAt(): Unit = { | |
val buf = newBuf | |
buf.append("foobar") | |
@@ -106,12 +112,12 @@ object StringBufferSuite extends tests.Suite { | |
buf.setCharAt(6, 'h')) | |
} | |
- test("ensureCapacity") { | |
+ @Test def ensureCapacity(): Unit = { | |
// test that ensureCapacity is linking | |
newBuf.ensureCapacity(10) | |
} | |
- test("should_properly_setLength") { | |
+ @Test def shouldProperlySetLength(): Unit = { | |
val buf = newBuf | |
buf.append("foobar") | |
@@ -121,7 +127,7 @@ object StringBufferSuite extends tests.Suite { | |
assertEquals("foo\u0000\u0000\u0000", { buf.setLength(6); buf.toString }) | |
} | |
- test("appendCodePoint") { | |
+ @Test def appendCodePoint(): Unit = { | |
val buf = newBuf | |
buf.appendCodePoint(0x61) | |
assertEquals("a", buf.toString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment