summaryrefslogtreecommitdiff
path: root/test/disabled/run/implicits-base.scala
blob: 06d017ed70b1f2375c5dec2becab498676c6c156 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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")
  }
}