ca52f554a1/org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/sourcegen/PrettyPrinterTest.scala

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
56
 * Bla bla
56
 * Bla bla
57
 * /
57
 * /
58
"""
58
"""
59
    val method = DocDef(DocComment(doc, NoPosition),mkDefDef(name = "meth", body = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree) :: Ident("()") :: Nil))
59
    val method = DocDef(DocComment(doc, NoPosition),mkDefDef(name = "meth", body = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree) :: Ident(newTermName("()")) :: Nil))
60
        
60
        
61
    val tree = mkCaseClass(
61
    val tree = mkCaseClass(
62
        name = "A",
62
        name = "A",
...
...
82
  
82
  
83
  @Test
83
  @Test
84
  def testCaseClassTwoArgLists() {
84
  def testCaseClassTwoArgLists() {
85
    val argsList1 = (NoMods, "r1", Ident("Rate")) :: Nil
85
    val argsList1 = (NoMods, "r1", Ident(newTermName("Rate"))) :: Nil
86
    val argsList2 = (NoMods, "r2", Ident("Rate")) :: (NoMods, "r3", Ident("Rate")) :: Nil
86
    val argsList2 = (NoMods, "r2", Ident(newTermName("Rate"))) :: (NoMods, "r3", Ident(newTermName("Rate"))) :: Nil
87
        
87
        
88
    mkCaseClass(name = "A", argss = List(argsList1, argsList2)) prettyPrintsTo "case class A(r1: Rate)(r2: Rate, r3: Rate)"
88
    mkCaseClass(name = "A", argss = List(argsList1, argsList2)) prettyPrintsTo "case class A(r1: Rate)(r2: Rate, r3: Rate)"
89
  }
89
  }
...
...
97
  def testCaseClassOneArg() = {
97
  def testCaseClassOneArg() = {
98
    mkCaseClass(
98
    mkCaseClass(
99
        name = "A", 
99
        name = "A", 
100
        argss = ((NoMods, "rate", Ident("Rate")) :: Nil) :: Nil) prettyPrintsTo "case class A(rate: Rate)"
100
        argss = ((NoMods, "rate", Ident(newTermName("Rate"))) :: Nil) :: Nil) prettyPrintsTo "case class A(rate: Rate)"
101
  }
101
  }
102
102
103
  @Test
103
  @Test
104
  def testCaseClassTwoArgs() = {
104
  def testCaseClassTwoArgs() = {
105
    mkCaseClass(
105
    mkCaseClass(
106
        name = "A", 
106
        name = "A", 
107
        argss = List(List((NoMods, "x", Ident("Int")), (NoMods, "y", Ident("String"))))) prettyPrintsTo "case class A(x: Int, y: String)"
107
        argss = List(List((NoMods, "x", Ident(newTermName("Int"))), (NoMods, "y", Ident(newTermName("String")))))) prettyPrintsTo "case class A(x: Int, y: String)"
108
  }
108
  }
109
109
110
  @Test
110
  @Test
111
  def testClassTwoArgs() = {
111
  def testClassTwoArgs() = {
112
    mkClass(
112
    mkClass(
113
        name = "A", 
113
        name = "A", 
114
        argss = List(List((NoMods, "x", Ident("Int")), (NoMods, "y", Ident("String"))))) prettyPrintsTo "class A(x: Int, y: String)"
114
        argss = List(List((NoMods, "x", Ident(newTermName("Int"))), (NoMods, "y", Ident(newTermName("String")))))) prettyPrintsTo "class A(x: Int, y: String)"
115
  }
115
  }
116
116
117
  @Test
117
  @Test
118
  def testClassTwoValVarArgs() = {
118
  def testClassTwoValVarArgs() = {
119
    mkClass(
119
    mkClass(
120
        name = "A", 
120
        name = "A", 
121
        argss = List(List((NoMods withPosition (Tokens.VAL, NoPosition), "x", Ident("Int")), (NoMods withPosition (Tokens.VAR, NoPosition), "y", Ident("String"))))) prettyPrintsTo "class A(val x: Int, var y: String)"
121
        argss = List(List((NoMods withPosition (Tokens.VAL, NoPosition), "x", Ident(newTermName("Int"))), (NoMods withPosition (Tokens.VAR, NoPosition), "y", Ident(newTermName("String")))))) prettyPrintsTo "class A(val x: Int, var y: String)"
122
  }
122
  }
123
  
123
  
124
  @Test
124
  @Test
...
...
126
    
126
    
127
    val tree = mkCaseClass(
127
    val tree = mkCaseClass(
128
        name = "A", 
128
        name = "A", 
129
        argss = ((NoMods, "x", Ident("Int")) :: Nil) :: Nil, 
129
        argss = ((NoMods, "x", Ident(newTermName("Int"))) :: Nil) :: Nil, 
130
        parents = Ident("X") :: Ident("Y") :: Nil)
130
        parents = Ident(newTermName("X")) :: Ident(newTermName("Y")) :: Nil)
131
    
131
    
132
    tree prettyPrintsTo "case class A(x: Int) extends X with Y"
132
    tree prettyPrintsTo "case class A(x: Int) extends X with Y"
133
  }
133
  }
...
...
137
    
137
    
138
    val tree = mkCaseClass(
138
    val tree = mkCaseClass(
139
        name = "A", 
139
        name = "A", 
140
        argss = ((NoMods, "x", Ident("Int")) :: Nil) :: Nil, 
140
        argss = ((NoMods, "x", Ident(newTermName("Int"))) :: Nil) :: Nil, 
141
        parents = Ident("X") :: Nil,
141
        parents = Ident(newTermName("X")) :: Nil,
142
        superArgs = Ident("x") :: Nil)
142
        superArgs = Ident(newTermName("x")) :: Nil)
143
    
143
    
144
    tree prettyPrintsTo "case class A(x: Int) extends X(x)"
144
    tree prettyPrintsTo "case class A(x: Int) extends X(x)"
145
  }
145
  }
...
...
178
          NoMods withPosition (Flags.IMPLICIT, NoPosition) withPosition (Flags.METHOD, NoPosition) ,
178
          NoMods withPosition (Flags.IMPLICIT, NoPosition) withPosition (Flags.METHOD, NoPosition) ,
179
          "eins",
179
          "eins",
180
          Nil,
180
          Nil,
181
          List(List(ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), "a", EmptyTree, EmptyTree))),
181
          List(List(ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), newTermName("a"), EmptyTree, EmptyTree))),
182
          EmptyTree,
182
          EmptyTree,
183
          Literal(Constant(()))
183
          Literal(Constant(()))
184
        )
184
        )
...
...
189
  @Test
189
  @Test
190
  def testDefDefWithTypeParams =  {
190
  def testDefDefWithTypeParams =  {
191
    
191
    
192
    val arg = ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), "a", 
192
    val arg = ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), newTermName("a"), 
193
                TypeDef(NoMods, "R".toTypeName, TypeDef(NoMods, "X".toTypeName, Nil, EmptyTree) :: Nil, EmptyTree), EmptyTree)
193
                TypeDef(NoMods, newTypeName("R"), TypeDef(NoMods, newTypeName("X"), Nil, EmptyTree) :: Nil, EmptyTree), EmptyTree)
194
    
194
    
195
    val tree = DefDef(
195
    val tree = DefDef(
196
          NoMods withPosition (Flags.METHOD, NoPosition) ,
196
          NoMods withPosition (Flags.METHOD, NoPosition) ,
197
          "m",
197
          "m",
198
          TypeDef(NoMods, "X".toTypeName, Nil, EmptyTree) :: Nil,
198
          TypeDef(NoMods, newTypeName("X"), Nil, EmptyTree) :: Nil,
199
          List(List(arg)),
199
          List(List(arg)),
200
          EmptyTree,
200
          EmptyTree,
201
          Literal(Constant(()))
201
          Literal(Constant(()))
...
...
209
209
210
    val doc = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree)
210
    val doc = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree)
211
    
211
    
212
    val tree = mkDefDef(name = "meth", body = doc :: Ident("()") :: Nil)
212
    val tree = mkDefDef(name = "meth", body = doc :: Ident(newTermName("()")) :: Nil)
213
    
213
    
214
    tree prettyPrintsTo """def meth() = {
214
    tree prettyPrintsTo """def meth() = {
215
  /** Kuuka */
215
  /** Kuuka */
...
...
219
  
219
  
220
  @Test
220
  @Test
221
  def testApplyHasParens() = {
221
  def testApplyHasParens() = {
222
    Apply(Ident( "aa" ), Nil) prettyPrintsTo """aa()"""
222
    Apply(Ident(newTermName("aa")), Nil) prettyPrintsTo """aa()"""
223
  }
223
  }
224
  
224
  
225
  @Test
225
  @Test
226
  def testApplyTypesToClass() = {
226
  def testApplyTypesToClass() = {
227
    TypeApply(Ident("MyClass"), Ident("A") :: Ident("B") :: Nil) prettyPrintsTo """MyClass[A, B]"""
227
    TypeApply(Ident(newTermName("MyClass")), Ident(newTermName("A")) :: Ident(newTermName("B")) :: Nil) prettyPrintsTo """MyClass[A, B]"""
228
  }
228
  }
229
  
229
  
230
  @Test
230
  @Test
231
  def testClassWithTypeParams() = {
231
  def testClassWithTypeParams() = {
232
    val c = mkClass(name = "A", tparams = List(TypeDef(NoMods, "T".toTypeName, Nil, EmptyTree), TypeDef(NoMods, "U".toTypeName, Nil, EmptyTree)))
232
    val c = mkClass(name = "A", tparams = List(TypeDef(NoMods, newTypeName("T"), Nil, EmptyTree), TypeDef(NoMods, newTypeName("U"), Nil, EmptyTree)))
233
    c prettyPrintsTo """class A[T, U]"""
233
    c prettyPrintsTo """class A[T, U]"""
234
  }
234
  }
235
  
235
  
236
  @Test
236
  @Test
237
  def testFloatLiteralFromIdent() = {
237
  def testFloatLiteralFromIdent() = {
238
   Ident( "33.3f") prettyPrintsTo """33.3f"""
238
   Ident(newTermName("33.3f")) prettyPrintsTo """33.3f"""
239
  }
239
  }
240
  
240
  
241
  @Test
241
  @Test
...
...
252
    val tree = DefDef(
252
    val tree = DefDef(
253
          NoMods withPosition (Flags.METHOD, NoPosition),
253
          NoMods withPosition (Flags.METHOD, NoPosition),
254
          "eins",
254
          "eins",
255
          TypeDef( NoMods, "R".toTypeName, Nil, TypeBoundsTree( EmptyTree, TypeDef( NoMods, "Rate".toTypeName, Nil, EmptyTree ))) :: Nil,
255
          TypeDef( NoMods, newTypeName("R"), Nil, TypeBoundsTree( EmptyTree, TypeDef( NoMods, newTypeName("Rate"), Nil, EmptyTree ))) :: Nil,
256
          Nil,
256
          Nil,
257
          EmptyTree,
257
          EmptyTree,
258
          Literal(Constant(()))
258
          Literal(Constant(()))