diff options
author | Vlad Ureche <vlad.ureche@gmail.com> | 2012-04-14 12:27:55 +0200 |
---|---|---|
committer | Vlad Ureche <vlad.ureche@gmail.com> | 2012-04-14 12:27:55 +0200 |
commit | 95ad0bbddb09f1177cf8cd6f0e8ef2f7135bf4ae (patch) | |
tree | aba57e721049cb455aa4134674047f0eeb15ef77 /test/scaladoc | |
parent | 651f2219b325c1a4cf586da4cae58e60caec0860 (diff) | |
download | scala-95ad0bbddb09f1177cf8cd6f0e8ef2f7135bf4ae.tar.gz scala-95ad0bbddb09f1177cf8cd6f0e8ef2f7135bf4ae.tar.bz2 scala-95ad0bbddb09f1177cf8cd6f0e8ef2f7135bf4ae.zip |
Adapted implicits testsuite for SIP18
Diffstat (limited to 'test/scaladoc')
-rw-r--r-- | test/scaladoc/resources/implicits-base-res.scala | 2 | ||||
-rw-r--r-- | test/scaladoc/resources/implicits-chaining-res.scala | 2 | ||||
-rw-r--r-- | test/scaladoc/resources/implicits-elimination-res.scala | 7 | ||||
-rw-r--r-- | test/scaladoc/resources/implicits-scopes-res.scala | 1 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-base.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-base.scala | 180 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-chaining.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-chaining.scala | 65 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-elimination.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-elimination.scala | 23 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-scopes.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/implicits-scopes.scala | 77 |
12 files changed, 360 insertions, 1 deletions
diff --git a/test/scaladoc/resources/implicits-base-res.scala b/test/scaladoc/resources/implicits-base-res.scala index db7ca4fa51..ce86ba8918 100644 --- a/test/scaladoc/resources/implicits-base-res.scala +++ b/test/scaladoc/resources/implicits-base-res.scala @@ -28,6 +28,8 @@ class A[T] { } /** Companion object with implicit transformations */ object A { + import language.implicitConversions // according to SIP18 + implicit def pimpA0[V](a: A[V]) = new PimpedA(a) implicit def pimpA1[ZBUR: Numeric](a: A[ZBUR]) = new NumericA[ZBUR](a) implicit def pimpA2(a: A[Int]) = new IntA(a) diff --git a/test/scaladoc/resources/implicits-chaining-res.scala b/test/scaladoc/resources/implicits-chaining-res.scala index b20c8f846c..c005d5fe09 100644 --- a/test/scaladoc/resources/implicits-chaining-res.scala +++ b/test/scaladoc/resources/implicits-chaining-res.scala @@ -3,6 +3,8 @@ */ package scala.test.scaladoc.implicits { + import language.implicitConversions // according to SIP18 + // the classes involved case class Z[U](a: U) case class Intermediate[T, U](t: T, u: U) diff --git a/test/scaladoc/resources/implicits-elimination-res.scala b/test/scaladoc/resources/implicits-elimination-res.scala index 68743aee06..b23667440c 100644 --- a/test/scaladoc/resources/implicits-elimination-res.scala +++ b/test/scaladoc/resources/implicits-elimination-res.scala @@ -2,8 +2,13 @@ * Testing scaladoc implicits elimination */ package scala.test.scaladoc.implicits.elimination { + + import language.implicitConversions // according to SIP18 + /** No conversion, as B doesn't bring any member */ class A class B { class C; trait V; type T; } - object A { implicit def toB(a: A): B = null } + object A { + implicit def toB(a: A): B = null + } } diff --git a/test/scaladoc/resources/implicits-scopes-res.scala b/test/scaladoc/resources/implicits-scopes-res.scala index 4e55c3e388..aaeb43f95b 100644 --- a/test/scaladoc/resources/implicits-scopes-res.scala +++ b/test/scaladoc/resources/implicits-scopes-res.scala @@ -2,6 +2,7 @@ * Testing scaladoc implicit scopes - looking for implicits in the right places */ package scala.test.scaladoc.implicits.scopes +import language.implicitConversions // according to SIP18 // TEST1 - In package object package object test1 { diff --git a/test/scaladoc/run/implicits-base.check b/test/scaladoc/run/implicits-base.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/implicits-base.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/implicits-base.scala b/test/scaladoc/run/implicits-base.scala new file mode 100644 index 0000000000..06d017ed70 --- /dev/null +++ b/test/scaladoc/run/implicits-base.scala @@ -0,0 +1,180 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest +import language._ + +object Test extends ScaladocModelTest { + + // test a file instead of a piece of code + override def resourceFile = "implicits-base-res.scala" + + // start implicits + def scaladocSettings = "-implicits -implicits-show-all" + + def testModel(root: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + // SEE THE test/resources/implicits-base-res.scala FOR THE EXPLANATION OF WHAT'S CHECKED HERE: + val base = root._package("scala")._package("test")._package("scaladoc")._package("implicits")._package("base") + var conv: ImplicitConversion = null + +//// class A /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val A = base._class("A") + + // the method pimped on by pimpA0 should be shadowed by the method in class A + assert(A._conversions(A.qualifiedName + ".pimpA0").isEmpty) + + // def convToNumericA: T // pimpA1: with a constraint that there is x: Numeric[T] implicit in scope + conv = A._conversion(A.qualifiedName + ".pimpA1") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToNumericA").resultType.name == "T") + + // def convToIntA: Int // pimpA2: with a constraint that T = Int + conv = A._conversion(A.qualifiedName + ".pimpA2") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToIntA").resultType.name == "Int") + + // def convToGtColonDoubleA: Double // pimpA3: with a constraint that T <: Double + conv = A._conversion(A.qualifiedName + ".pimpA3") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToGtColonDoubleA").resultType.name == "Double") + + // def convToPimpedA: S // pimpA4: with 3 constraints: T = Foo[Bar[S]], S: Foo and S: Bar + conv = A._conversion(A.qualifiedName + ".pimpA4") + assert(conv.members.length == 1) + assert(conv.constraints.length == 3) + assert(conv._member("convToPimpedA").resultType.name == "S") + + // def convToPimpedA: Bar[Foo[T]] // pimpA5: no constraints + conv = A._conversion(A.qualifiedName + ".pimpA5") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToPimpedA").resultType.name == "Bar[Foo[T]]") + + // def convToMyNumericA: T // pimpA6: with a constraint that there is x: MyNumeric[T] implicit in scope + conv = A._conversion(A.qualifiedName + ".pimpA6") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToMyNumericA").resultType.name == "T") + + // def convToManifestA: T // pimpA7: with 2 constraints: T: Manifest and T <: Double + // def convToTraversableOps: T // pimpA7: with 2 constraints: T: Manifest and T <: Double + // should not be abstract! + conv = A._conversion(A.qualifiedName + ".pimpA7") + assert(conv.members.length == 2) + assert(conv.constraints.length == 2) + assert(conv._member("convToManifestA").resultType.name == "T") + assert(conv._member("convToTraversableOps").resultType.name == "T") + assert(conv._member("convToTraversableOps").flags.toString.indexOf("abstract") == -1) + +//// class B /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val B = base._class("B") + + // these conversions should not affect B + assert(B._conversions(A.qualifiedName + ".pimpA0").isEmpty) + assert(B._conversions(A.qualifiedName + ".pimpA2").isEmpty) + assert(B._conversions(A.qualifiedName + ".pimpA4").isEmpty) + + // def convToNumericA: Double // pimpA1: no constraintsd + conv = B._conversion(A.qualifiedName + ".pimpA1") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToNumericA").resultType.name == "Double") + + // def convToGtColonDoubleA: Double // pimpA3: no constraints + conv = B._conversion(A.qualifiedName + ".pimpA3") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToGtColonDoubleA").resultType.name == "Double") + + // def convToPimpedA: Bar[Foo[Double]] // pimpA5: no constraints + conv = B._conversion(A.qualifiedName + ".pimpA5") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToPimpedA").resultType.name == "Bar[Foo[Double]]") + + // def convToMyNumericA: Double // pimpA6: (if showAll is set) with a constraint that there is x: MyNumeric[Double] implicit in scope + conv = B._conversion(A.qualifiedName + ".pimpA6") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToMyNumericA").resultType.name == "Double") + + // def convToManifestA: Double // pimpA7: no constraints + // def convToTraversableOps: Double // pimpA7: no constraints + // // should not be abstract! + conv = B._conversion(A.qualifiedName + ".pimpA7") + assert(conv.members.length == 2) + assert(conv.constraints.length == 0) + assert(conv._member("convToManifestA").resultType.name == "Double") + assert(conv._member("convToTraversableOps").resultType.name == "Double") + assert(conv._member("convToTraversableOps").flags.toString.indexOf("abstract") == -1) + +//// class C /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val C = base._class("C") + + // these conversions should not affect C + assert(C._conversions(A.qualifiedName + ".pimpA0").isEmpty) + assert(C._conversions(A.qualifiedName + ".pimpA3").isEmpty) + assert(C._conversions(A.qualifiedName + ".pimpA4").isEmpty) + assert(C._conversions(A.qualifiedName + ".pimpA7").isEmpty) + + // def convToNumericA: Int // pimpA1: no constraints + conv = C._conversion(A.qualifiedName + ".pimpA1") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToNumericA").resultType.name == "Int") + + // def convToIntA: Int // pimpA2: no constraints + conv = C._conversion(A.qualifiedName + ".pimpA2") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToIntA").resultType.name == "Int") + + // def convToPimpedA: Bar[Foo[Int]] // pimpA5: no constraints + conv = C._conversion(A.qualifiedName + ".pimpA5") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToPimpedA").resultType.name == "Bar[Foo[Int]]") + + // def convToMyNumericA: Int // pimpA6: (if showAll is set) with a constraint that there is x: MyNumeric[Int] implicit in scope + conv = C._conversion(A.qualifiedName + ".pimpA6") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToMyNumericA").resultType.name == "Int") + +//// class D /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val D = base._class("D") + + // these conversions should not affect D + assert(D._conversions(A.qualifiedName + ".pimpA0").isEmpty) + assert(D._conversions(A.qualifiedName + ".pimpA2").isEmpty) + assert(D._conversions(A.qualifiedName + ".pimpA3").isEmpty) + assert(D._conversions(A.qualifiedName + ".pimpA4").isEmpty) + assert(D._conversions(A.qualifiedName + ".pimpA7").isEmpty) + + // def convToNumericA: String // pimpA1: (if showAll is set) with a constraint that there is x: Numeric[String] implicit in scope + conv = D._conversion(A.qualifiedName + ".pimpA1") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToNumericA").resultType.name == "String") + + // def convToPimpedA: Bar[Foo[String]] // pimpA5: no constraints + conv = D._conversion(A.qualifiedName + ".pimpA5") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + assert(conv._member("convToPimpedA").resultType.name == "Bar[Foo[String]]") + + // def convToMyNumericA: String // pimpA6: (if showAll is set) with a constraint that there is x: MyNumeric[String] implicit in scope + conv = D._conversion(A.qualifiedName + ".pimpA6") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + assert(conv._member("convToMyNumericA").resultType.name == "String") + } +} diff --git a/test/scaladoc/run/implicits-chaining.check b/test/scaladoc/run/implicits-chaining.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/implicits-chaining.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/implicits-chaining.scala b/test/scaladoc/run/implicits-chaining.scala new file mode 100644 index 0000000000..858ca9ce61 --- /dev/null +++ b/test/scaladoc/run/implicits-chaining.scala @@ -0,0 +1,65 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest +import language._ + +object Test extends ScaladocModelTest { + + // test a file instead of a piece of code + override def resourceFile = "implicits-chaining-res.scala" + + // start implicits + def scaladocSettings = "-implicits" + + def testModel(root: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + // SEE THE test/resources/implicits-chaining-res.scala FOR THE EXPLANATION OF WHAT'S CHECKED HERE: + val base = root._package("scala")._package("test")._package("scaladoc")._package("implicits")._object("chaining") + var conv: ImplicitConversion = null + +//// class A /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val A = base._class("A") + + conv = A._conversion(base.qualifiedName + ".convertToZ") + assert(conv.members.length == 1) + assert(conv.constraints.length == 1) + +//// class B /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val B = base._class("B") + + conv = B._conversion(base.qualifiedName + ".convertToZ") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + +//// class C /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val C = base._class("C") + + assert(C._conversions(base.qualifiedName + ".convertToZ").isEmpty) + +//// class D /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val D = base._class("D") + + conv = D._conversion(base.qualifiedName + ".convertToZ") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + +//// class E /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val E = base._class("E") + + conv = E._conversion(base.qualifiedName + ".convertToZ") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + +//// class F /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val F = base._class("F") + + assert(F._conversions(base.qualifiedName + ".convertToZ").isEmpty) + } +} diff --git a/test/scaladoc/run/implicits-elimination.check b/test/scaladoc/run/implicits-elimination.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/implicits-elimination.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/implicits-elimination.scala b/test/scaladoc/run/implicits-elimination.scala new file mode 100644 index 0000000000..ed37b9cd90 --- /dev/null +++ b/test/scaladoc/run/implicits-elimination.scala @@ -0,0 +1,23 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest +import language._ + +object Test extends ScaladocModelTest { + + // test a file instead of a piece of code + override def resourceFile = "implicits-elimination-res.scala" + + // start implicits + def scaladocSettings = "-implicits" + + def testModel(root: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + // SEE THE test/resources/implicits-elimination-res.scala FOR THE EXPLANATION OF WHAT'S CHECKED HERE: + val base = root._package("scala")._package("test")._package("scaladoc")._package("implicits")._package("elimination") + val A = base._class("A") + + assert(A._conversions(A.qualifiedName + ".toB").isEmpty) + } +} diff --git a/test/scaladoc/run/implicits-scopes.check b/test/scaladoc/run/implicits-scopes.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/implicits-scopes.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/implicits-scopes.scala b/test/scaladoc/run/implicits-scopes.scala new file mode 100644 index 0000000000..7b9e80e148 --- /dev/null +++ b/test/scaladoc/run/implicits-scopes.scala @@ -0,0 +1,77 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest +import language._ + +object Test extends ScaladocModelTest { + + // test a file instead of a piece of code + override def resourceFile = "implicits-scopes-res.scala" + + // start implicits + def scaladocSettings = "-implicits" + + def testModel(root: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + var conv: ImplicitConversion = null + + // SEE THE test/resources/implicits-chaining-res.scala FOR THE EXPLANATION OF WHAT'S CHECKED HERE: + val base = root._package("scala")._package("test")._package("scaladoc")._package("implicits")._package("scopes") + +//// test1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val doTest1 = { + val test1 = base._package("test1") + val A = test1._class("A") + + conv = A._conversion(test1.qualifiedName + ".package.toB") // the .package means it's the package object + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + } + +//// test2 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val doTest2 = { + val test2 = base._package("test2") + val classes = test2._package("classes") + val A = classes._class("A") + + assert(A._conversions(test2.qualifiedName + ".toB").isEmpty) + } + +//// test3 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val doTest3 = { + val test3 = base._package("test3") + val A = test3._class("A") + + conv = A._conversion(A.qualifiedName + ".toB") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + } + +//// test4 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val doTest4 = { + val test4 = base._package("test4") + val A = test4._class("A") + val S = test4._object("S") + + conv = A._conversion(S.qualifiedName + ".toB") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + } + +//// test5 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + val doTest5 = { + val test5 = base._package("test5") + val scope = test5._object("scope") + val A = scope._class("A") + + conv = A._conversion(scope.qualifiedName + ".toB") + assert(conv.members.length == 1) + assert(conv.constraints.length == 0) + } + } +} |