summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-11-02 10:25:25 +0000
committermichelou <michelou@epfl.ch>2006-11-02 10:25:25 +0000
commitd9ba6d6db90bcf0bbb34e706bcad8e2c316bce8f (patch)
tree44868afb7e631e12fb43d02dedf5879f3de6229a
parent6aa668e0f46a5bc19016350d0f90bde3403c854d (diff)
downloadscala-d9ba6d6db90bcf0bbb34e706bcad8e2c316bce8f.tar.gz
scala-d9ba6d6db90bcf0bbb34e706bcad8e2c316bce8f.tar.bz2
scala-d9ba6d6db90bcf0bbb34e706bcad8e2c316bce8f.zip
added tests for rich characters
-rw-r--r--src/library/scala/runtime/RichChar.scala14
-rw-r--r--src/library/scala/xml/Utility.scala2
-rw-r--r--test/files/run/richs.check9
-rw-r--r--test/files/run/richs.scala41
4 files changed, 52 insertions, 14 deletions
diff --git a/src/library/scala/runtime/RichChar.scala b/src/library/scala/runtime/RichChar.scala
index 4e7a4752f7..39159db4e1 100644
--- a/src/library/scala/runtime/RichChar.scala
+++ b/src/library/scala/runtime/RichChar.scala
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
@@ -8,25 +8,25 @@
// $Id$
-
package scala.runtime
-
import java.lang.Character
final class RichChar(c: Char) {
- def isWhitespace: Boolean = Character.isWhitespace(c)
+ def asDigit: Int = Character.digit(c, Character.MAX_RADIX)
+ def asDigit(radix: Int): Int = Character.digit(c, radix)
+
+ def isControl: Boolean = Character.isISOControl(c)
def isDigit: Boolean = Character.isDigit(c)
+ def isISOControl: Boolean = Character.isISOControl(c)
def isLetter: Boolean = Character.isLetter(c)
def isLetterOrDigit: Boolean = Character.isLetterOrDigit(c)
def isLowerCase: Boolean = Character.isLowerCase(c)
def isUpperCase: Boolean = Character.isUpperCase(c)
- def isControl: Boolean = Character.isISOControl(c)
+ def isWhitespace: Boolean = Character.isWhitespace(c)
def toLowerCase: Char = Character.toLowerCase(c)
def toUpperCase: Char = Character.toUpperCase(c)
- def asDigit: Int = Character.digit(c, Character.MAX_RADIX)
-
}
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala
index 0072f120fa..fdc6681b5c 100644
--- a/src/library/scala/xml/Utility.scala
+++ b/src/library/scala/xml/Utility.scala
@@ -435,7 +435,7 @@ object Utility extends AnyRef with parsing.TokenTests {
else
i = i * base + ch().asDigit
case _ =>
- reportSyntaxError("character '" + ch() + " not allowed in char ref\n")
+ reportSyntaxError("character '" + ch() + "' not allowed in char ref\n")
}
nextch()
}
diff --git a/test/files/run/richs.check b/test/files/run/richs.check
index 3b2f468010..3b73f084a0 100644
--- a/test/files/run/richs.check
+++ b/test/files/run/richs.check
@@ -1,4 +1,13 @@
+RichCharTest1:
+true
+true
+true
+true
+
+RichCharTest2:
+true
+
RichIntTest:
10
11
diff --git a/test/files/run/richs.scala b/test/files/run/richs.scala
index 8b2775ea7b..a88a3c1237 100644
--- a/test/files/run/richs.scala
+++ b/test/files/run/richs.scala
@@ -14,10 +14,37 @@ trait RichTest {
def length[A](it: Iterator[A]) = it.toList length
def run: Unit
}
+object RichCharTest1 extends RichTest {
+ def run {
+ Console.println("\n" + getObjectName + ":")
+ Console.println('\40'.isWhitespace)
+ Console.println('\011'.isWhitespace)
+ Console.println('1'.asDigit == java.lang.Character.digit('1', 10))
+ Console.println('A'.asDigit(16) == java.lang.Character.digit('A', 16))
+ }
+}
+object RichCharTest2 extends RichTest {
+ case class C(s: String) {
+ private val it = s.elements
+ private var c: Char = _
+ def ch(): Char = c
+ def nextch(): Unit = { c = if (it.hasNext) it.next else ';' }
+ def err(msg: String) = Console.println(msg)
+ nextch()
+ }
+ def run {
+ Console.println("\n" + getObjectName + ":")
+ val c1 = C("x4A;")
+ val s1 = xml.Utility.parseCharRef(c1.ch, c1.nextch, c1.err)
+ val c2 = C("74;")
+ val s2 = xml.Utility.parseCharRef(c2.ch, c2.nextch, c2.err)
+ Console.println(s1 == s2)
+ }
+}
object RichIntTest extends RichTest {
private val n = 10
private val m = -2
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.println(length(0 until n))
Console.println(length(0 to n))
@@ -28,7 +55,7 @@ object RichIntTest extends RichTest {
}
}
object RichStringTest1 extends RichTest {
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.println("s1: " + s1)
Console.println("s2: " + s2)
@@ -38,7 +65,7 @@ object RichStringTest1 extends RichTest {
}
}
object RichStringTest2 extends RichTest {
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.print("s1: "); s1.lines foreach Console.println
Console.print("s2: "); s2.lines foreach Console.println
@@ -48,7 +75,7 @@ object RichStringTest2 extends RichTest {
}
}
object RichStringTest3 extends RichTest {
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.println("s1: " + s1.stripLineEnd)
Console.println("s2: " + s2.stripLineEnd)
@@ -58,7 +85,7 @@ object RichStringTest3 extends RichTest {
}
}
object RichStringTest4 extends RichTest {
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.println("s1: " + s1.stripMargin)
Console.println("s2: " + s2.stripMargin)
@@ -68,7 +95,7 @@ object RichStringTest4 extends RichTest {
}
}
object RichStringTest5 extends RichTest {
- def run: Unit = {
+ def run {
Console.println("\n" + getObjectName + ":")
Console.println("s1: " + s3.stripMargin('#'))
Console.println("s2: " + s3.stripMargin('#'))
@@ -79,6 +106,8 @@ object RichStringTest5 extends RichTest {
}
object Test {
def main(args: Array[String]): Unit = {
+ RichCharTest1.run
+ RichCharTest2.run
RichIntTest.run
RichStringTest1.run
RichStringTest2.run