diff options
author | Burak Emir <emir@epfl.ch> | 2007-03-02 19:07:57 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2007-03-02 19:07:57 +0000 |
commit | 61b2debaa00361250fbee05cbb71f2c989ad2c03 (patch) | |
tree | 7e4ed39511700f88f7b68a695fcf18ef67366ecf /src | |
parent | a1c87639762b2b9172c1a775fbd3cfaa66536ab0 (diff) | |
download | scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.tar.gz scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.tar.bz2 scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.zip |
* small lib addition to testing.SUnit, made Uni...
* small lib addition to testing.SUnit, made UnitTest @deprecated added
* xml pattern matching on prefixes (in SymbolicXMLBuilder) xml name
* parsing ensures that names do not end in a colon (namespaces) rewrote
* xml02 to use SUnit
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala | 31 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala | 14 | ||||
-rw-r--r-- | src/library/scala/testing/SUnit.scala | 83 | ||||
-rw-r--r-- | src/library/scala/testing/UnitTest.scala | 2 |
4 files changed, 95 insertions, 35 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala index 1da2a5e779..3c1a7f3dd1 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala @@ -390,23 +390,30 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean } - /** Name ::= (Letter | '_' | ':') (NameChar)* + /** actually, Name ::= (Letter | '_' | ':') (NameChar)* but starting with ':' cannot happen + ** Name ::= (Letter | '_') (NameChar)* * * see [5] of XML 1.0 specification + * + * pre-condition: ch != ':' // assured by definition of XMLSTART token + * post-condition: name does neither start, nor end in ':' */ /*[Duplicate]*/ def xName: String = { - if( xml.Parsing.isNameStart( ch ) ) { - do { - putChar( ch ); - nextch; - } while( xml.Parsing.isNameChar( ch ) ); - val n = cbuf.toString().intern(); - cbuf.setLength( 0 ); - n - } else { - reportSyntaxError( "name expected, but char '"+ch+"' cannot start a name" ); - new String(); + if( !xml.Parsing.isNameStart( ch ) ) { + reportSyntaxError( "name expected, but char '"+ch+"' cannot start a name" ) + return "" } + do { + putChar( ch ) + nextch + } while( xml.Parsing.isNameChar( ch ) ) + if(':' == cbuf.charAt(cbuf.length-1)) { + reportSyntaxError( "name cannot end in ':'" ) + cbuf.setLength(cbuf.length-1) + } + val n = cbuf.toString().intern() + cbuf.setLength( 0 ) + n } diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala index e06581bdbc..de28a75e64 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala @@ -158,14 +158,22 @@ abstract class SymbolicXMLBuilder(make: TreeBuilder, p: Parsers # Parser, preser New(_scala_xml_ProcInstr, LL(target, txt)) /** @todo: attributes */ - def makeXMLpat(pos: int, n: String, args: mutable.Buffer[Tree]): Tree = + def makeXMLpat(pos: int, n: String, args: mutable.Buffer[Tree]): Tree = { + val (prepat, labpat) = n.indexOf(':') match { + case -1 => (Ident(nme.WILDCARD), Literal(Constant(n))) + //case 0 => // is erroneous, but cannot happen + case i => //if(i+1<n.length) // we ensure i+1<n.length in method xName + (Literal(Constant(n.substring(0,i))), Literal(Constant(n.substring(i+1,n.length)))) + //else { p.syntaxError(pos,"nonsensical qualified name in XML"); return Ident(nme.WILDCARD).setPos(pos)} + } mkXML(pos, true, - Ident( nme.WILDCARD ), - Literal(Constant(n)), + prepat, //Ident( nme.WILDCARD ), + labpat, //Literal(Constant(n)), null, //Array[Tree](), null, args); + } protected def convertToTextPat(t: Tree): Tree = t match { case _:Literal => makeTextPat(t) diff --git a/src/library/scala/testing/SUnit.scala b/src/library/scala/testing/SUnit.scala index 63d0dd6c34..4ab93db976 100644 --- a/src/library/scala/testing/SUnit.scala +++ b/src/library/scala/testing/SUnit.scala @@ -40,9 +40,26 @@ import compat.StringBuilder * Console.println(tf.toString()) * } * </pre> + * + * The trait TestConsoleMain contains this code as a main method, for convenience. */ object SUnit { + /** convenience trait, mix it in a TestMain object and implement "suite" to get this code + * <b>val</b> r = <b>new</b> TestResult() + * suite.run(r) + * <b>for</b> (<b>val</b> tf <- r.failures()) { + * Console.println(tf.toString()) + */ + trait TestConsoleMain { + def suite: TestSuite + def main(args:Array[String]) { + val r = new TestResult() + suite.run(r) + for (val tf <- r.failures()) + Console.println(tf.toString()) + } + } /** a Test can be run with its result being collected */ trait Test { def run(r: TestResult): Unit @@ -131,59 +148,85 @@ object SUnit { /** this class defined useful assert methods */ trait Assert { - /** equality */ + /** fails if expected != actual */ def assertEquals[A](msg: String, expected: A, actual: => A): Unit = if (expected != actual) fail(msg) - /** equality */ + /** fails if expected != actual */ def assertEquals[A](expected: A, actual: => A): Unit = assertEquals("(no message)", expected, actual) - /** falseness */ + /** succeeds if actual is false */ def assertFalse(msg: String, actual: => Boolean): Unit = assertEquals(msg, false, actual) - /** falseness */ + /** succeeds if actual is false */ def assertFalse(actual: => Boolean): Unit = assertFalse("(no message)", actual) - /** not null */ + /** fails if null eq actual */ def assertNotNull(msg:String, actual: => AnyRef): Unit = - if (null == actual) fail(msg) + if (null eq actual) fail(msg) - /** not null */ + /** fails if null eq actual */ def assertNotNull(actual: => AnyRef): Unit = assertNotNull("(no message)", actual) - /** reference inequality */ - def assertNotSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = + /** + * @deprecated use assertNotEq instead + */ + @deprecated def assertNotSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = if (expected.eq(actual)) fail(msg) - /** reference inequality */ - def assertNotSame(expected: => AnyRef, actual: => AnyRef): Unit = - assertNotSame("(no message)", expected, actual) + /** + * @deprecated use assertNotEq instead + */ + @deprecated def assertNotSame(expected: => AnyRef, actual: => AnyRef): Unit = + assertNotEq("(no message)", expected, actual) + + /** fail if expected eq actual */ + def assertNotEq(msg: String, expected => AnyRef, actual: => AnyRef) { + if (expected eq actual) fail(msg) + } - /** null */ + /** fail if expected eq actual */ + def assertNotEq(msg: String, expected => AnyRef, actual: => AnyRef) { + assertNotEq("(no message)", expected, actual) + } + + /** fails if actual ne null */ def assertNull(msg: String, actual: => AnyRef): Unit = - if (null != actual) fail(msg) + if (null ne actual) fail(msg) - /** null */ + /** fails if actual ne null */ def assertNull(actual: => AnyRef): Unit = assertNull("(no message)", actual) - /** reference equality */ + /** + * @deprecated use assertEq instead + */ def assertSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = if(!expected.eq(actual)) fail(msg) - /** reference equality */ + /** + * @deprecated use assertEq instead + */ def assertSame(expected: => AnyRef, actual: => AnyRef): Unit = - assertSame("(no message)", expected, actual) + assertEq("(no message)", expected, actual) + + /** fails if expected ne actual */ + def assertEq(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = + if(expected ne actual) fail(msg) + + /** fails if expected ne actual */ + def assertEq(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = + assertEq("(no message)", expected, actual) - /** trueness */ + /** succeeds if actual == true */ def assertTrue(msg: String, actual: => Boolean): Unit = assertEquals(msg, true, actual) - /** trueness */ + /** succeeds if actual == true */ def assertTrue(actual: => Boolean): Unit = assertTrue("(no message)", actual) diff --git a/src/library/scala/testing/UnitTest.scala b/src/library/scala/testing/UnitTest.scala index 302ab6dc4a..db2eab6f4e 100644 --- a/src/library/scala/testing/UnitTest.scala +++ b/src/library/scala/testing/UnitTest.scala @@ -15,7 +15,9 @@ package scala.testing /** * Some simple methods to support unit testing with assertions * to contain more JUnit style assertions which use Scala's features. + * @deprecated use SUnit instead */ +@deprecated object UnitTest { class Report(report_ok: () => Unit, report_fail: (String,String) => Unit) { |