Skip to content

Commit 48a1a0e

Browse files
committed
Fix tests and library to work with indentation
Also, add a test where definition ends at end of file
1 parent bd8a40e commit 48a1a0e

19 files changed

+104
-107
lines changed

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ object Liftable {
5858
given ArrayOfBooleanIsLiftable as Liftable[Array[Boolean]] = new Liftable[Array[Boolean]] {
5959
def toExpr(array: Array[Boolean]): given QuoteContext => Expr[Array[Boolean]] =
6060
if (array.length == 0) '{ Array.emptyBooleanArray }
61-
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
61+
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
6262
}
6363

6464
given ArrayOfByteIsLiftable as Liftable[Array[Byte]] = new Liftable[Array[Byte]] {
6565
def toExpr(array: Array[Byte]): given QuoteContext => Expr[Array[Byte]] =
6666
if (array.length == 0) '{ Array.emptyByteArray }
67-
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
67+
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
6868
}
6969

7070
given ArrayOfShortIsLiftable as Liftable[Array[Short]] = new Liftable[Array[Short]] {

tests/new/test.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
trait T {
22
object O
33
}
4-
5-
object Test0 {
6-
trait A[T]
7-
given a[T] as A[T]
8-
9-
class B[T]
10-
given b[T] as B[T]
11-
}
12-
13-
class C extends T
14-
15-
object Test {
16-
val c = new C
17-
c.O
18-
}

tests/pos/indent.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ object Test:
3535
val y = x * x
3636
y + y
3737

38+
xs.map { x =>
39+
val y = x * x
40+
if y >= 0 then
41+
val z = y + y
42+
println(z)
43+
y + 1
44+
}
45+
3846
println(f(2) + g)
3947

4048
(new Test2).foo
@@ -104,4 +112,7 @@ class Coder(words: List[String]):
104112
case _ => false
105113
.flatMap:
106114
case (digit, str) => str map (ltr => ltr -> digit)
107-
end Coder
115+
end Coder
116+
117+
object Test22
118+
def foo: Int = 22

tests/pos/t2171.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ final object test {
22
def logIgnoredException(msg: => String) =
33
try 0 catch { case ex => println(msg) }
44

5-
def main (args: Array[String]): Unit =
6-
while (true) logIgnoredException ("...")
5+
def main (args: Array[String]): Unit =
6+
while (true) logIgnoredException ("...")
77
}

tests/run-macros/f-interpolator-neg/Tests_2.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
22

3-
def main(args: Array[String]): Unit = {
3+
def main(args: Array[String]): Unit = {
44
val s = "Scala"
55
val d = 8
66
val b = false
@@ -10,7 +10,7 @@ object Test {
1010
val x = new java.util.Formattable {
1111
def formatTo(ff: java.util.Formatter, g: Int, w: Int, p: Int): Unit = ff format "xxx"
1212
}
13-
numberArgumentsTests(s, d)
13+
numberArgumentsTests(s, d)
1414
interpolationMismatches(s, f, b)
1515
flagMismatches(s, c, d, f, t)
1616
badPrecisions(c, d, f, t)
@@ -19,7 +19,7 @@ object Test {
1919
badArgTypes(s)
2020
misunderstoodConversions(t, s)
2121
otherBrainFailures(d)
22-
}
22+
}
2323

2424
def numberArgumentsTests(s : String, d : Int) = {
2525
import TestFooErrors._
@@ -115,7 +115,7 @@ object Test {
115115
assertEquals(foo"%%bci.2${'i'}%..2c2", List((true, 0, 1, 0, "Missing conversion operator in '%'; use %% for literal %, %n for newline")))
116116
}
117117

118-
def assertEquals(actual: Any, expected: Any): Unit = {
119-
assert(actual == expected, s"actual: $actual\nbut expected: $expected")
120-
}
121-
}
118+
def assertEquals(actual: Any, expected: Any): Unit = {
119+
assert(actual == expected, s"actual: $actual\nbut expected: $expected")
120+
}
121+
}

tests/run-macros/i4734/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object Macros {
2727
def foreach(f: Int => Expr[Unit]) given QuoteContext: Expr[Unit] = {
2828
@tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] =
2929
if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc })
30-
else acc
30+
else acc
3131
loop(end - 1, '{})
3232
}
3333
}

tests/run-macros/i4735/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Macro {
2929
def foreach(f: Int => Expr[Unit]) given QuoteContext: Expr[Unit] = {
3030
@tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] =
3131
if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc })
32-
else acc
32+
else acc
3333
loop(end - 1, '{})
3434
}
3535
}

tests/run/Course-2002-04.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ object M1 {
5959
var i = l;
6060
var j = r;
6161
While (i <= j) {
62-
While (less(xs(i), pivot)) { i = i + 1 }
63-
While (less(pivot, xs(j))) { j = j - 1 }
64-
if (i <= j) {
65-
swap(i, j);
66-
i = i + 1;
67-
j = j - 1;
68-
}
62+
While (less(xs(i), pivot)) { i = i + 1 }
63+
While (less(pivot, xs(j))) { j = j - 1 }
64+
if (i <= j) {
65+
swap(i, j);
66+
i = i + 1;
67+
j = j - 1;
68+
}
6969
}
7070
if (l < j) sort1(l, j);
7171
if (j < r) sort1(i, r);

tests/run/Course-2002-08.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ abstract class CircuitSimulator() extends BasicCircuitSimulator() {
517517
def demux2(in: Wire, ctrl: List[Wire], out: List[Wire]) : Unit = {
518518
val ctrlN = ctrl.map(w => { val iw = new Wire(); inverter(w,iw); iw});
519519
val w0 = new Wire();
520-
val w1 = new Wire();
521-
val w2 = new Wire();
522-
val w3 = new Wire();
520+
val w1 = new Wire();
521+
val w2 = new Wire();
522+
val w3 = new Wire();
523523

524524
andGate(in, ctrl(1), w3);
525525
andGate(in, ctrl(1), w2);

tests/run/Course-2002-13.scala

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class Tokenizer(s: String, delimiters: String) extends Iterator[String] {
2323
var ch = s.charAt(i); i = i + 1;
2424
if (isDelimiter(ch)) ch.toString()
2525
else {
26-
while (i < s.length() &&
27-
s.charAt(i) > ' ' &&
28-
!isDelimiter(s.charAt(i))){ i = i + 1 }
29-
s.substring(start, i)
26+
while (i < s.length() &&
27+
s.charAt(i) > ' ' &&
28+
!isDelimiter(s.charAt(i))){ i = i + 1 }
29+
s.substring(start, i)
3030
}
3131
} else "";
3232

@@ -100,8 +100,8 @@ object Terms {
100100
case (List(), List()) => Some(s)
101101
case (x :: xs1, y :: ys1) =>
102102
unify(x, y, s) match {
103-
case Some(s1) => unify(xs1, ys1, s1)
104-
case None => None
103+
case Some(s1) => unify(xs1, ys1, s1)
104+
case None => None
105105
}
106106
case _ => None
107107
}
@@ -136,14 +136,14 @@ object Programs {
136136

137137
def solve2(query: List[Term], s: Subst): LazyList[Subst] = query match {
138138
case List() =>
139-
LazyList.cons(s, LazyList.empty)
139+
LazyList.cons(s, LazyList.empty)
140140
case Con("not", qs) :: query1 =>
141-
if (solve1(qs, s).isEmpty) LazyList.cons(s, LazyList.empty)
142-
else LazyList.empty
141+
if (solve1(qs, s).isEmpty) LazyList.cons(s, LazyList.empty)
142+
else LazyList.empty
143143
case q :: query1 =>
144-
for (clause <- list2stream(clauses);
145-
s1 <- tryClause(clause.newInstance, q, s);
146-
s2 <- solve1(query1, s1)) yield s2
144+
for (clause <- list2stream(clauses);
145+
s1 <- tryClause(clause.newInstance, q, s);
146+
s2 <- solve1(query1, s1)) yield s2
147147
}
148148

149149
def solve1(query: List[Term], s: Subst): LazyList[Subst] = {
@@ -200,7 +200,7 @@ class Parser(s: String) {
200200
token = it.next;
201201
Clause(NoTerm, rep(constructor));
202202
} else {
203-
Clause(
203+
Clause(
204204
constructor,
205205
if (token equals ":-") { token = it.next; rep(constructor) } else List())
206206
}
@@ -219,27 +219,27 @@ object Prolog {
219219
var tvs: List[String] = List();
220220
{ input =>
221221
new Parser(input).all foreach { c =>
222-
if (c.lhs == NoTerm) {
223-
c.rhs match {
224-
case List(Con("more", List())) =>
222+
if (c.lhs == NoTerm) {
223+
c.rhs match {
224+
case List(Con("more", List())) =>
225225
solutions = solutions.tail;
226-
case _ =>
226+
case _ =>
227227
solutions = solve(c.rhs, program);
228-
tvs = c.tyvars;
228+
tvs = c.tyvars;
229229
}
230-
if (solutions.isEmpty) {
231-
Console.println("no")
232-
} else {
233-
val s: Subst = solutions.head
234-
.filter(b => tvs contains b.name)
235-
.map(b => Binding(b.name, b.term map solutions.head))
230+
if (solutions.isEmpty) {
231+
Console.println("no")
232+
} else {
233+
val s: Subst = solutions.head
234+
.filter(b => tvs contains b.name)
235+
.map(b => Binding(b.name, b.term map solutions.head))
236236
.reverse;
237-
if (s.isEmpty) Console.println("yes")
238-
else Console.println(s);
237+
if (s.isEmpty) Console.println("yes")
238+
else Console.println(s);
239239
}
240-
} else {
241-
program = program ::: List(c);
242-
}
240+
} else {
241+
program = program ::: List(c);
242+
}
243243
}
244244
}
245245
}

tests/run/companion-loading.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ implicit object FooAssoc extends Assoc[Foo] {
1919
def foo(t: Foo): Int = t.i
2020
}
2121

22-
inline def link[T] = delegate match {
23-
case _: Link[T, s] =>
24-
delegate match {
25-
case stuff: s => stuff
26-
}
27-
}
22+
inline def link[T] <: Any =
23+
delegate match {
24+
case _: Link[T, s] =>
25+
delegate match {
26+
case stuff: s => stuff
27+
}
28+
}
2829

2930
object Test {
3031
println(s"Test")

tests/run/iq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object iq {
4040
q2
4141
}
4242
else {
43-
val (head, q3) = q2.dequeue
43+
val (head, q3) = q2.dequeue
4444
Console.println("Head: " + head)
4545
q3
4646
}

tests/run/lists-run.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ min cardinality(ys, e)))
6969
}, "obey min cardinality")
7070
assert({
7171
val intersection = xs intersect ys
72-
val unconsumed = xs.foldLeft(intersection){(rest, e) =>
73-
if (! rest.isEmpty && e == rest.head) rest.tail else rest
74-
}
75-
unconsumed.isEmpty
72+
val unconsumed = xs.foldLeft(intersection){(rest, e) =>
73+
if (! rest.isEmpty && e == rest.head) rest.tail else rest
74+
}
75+
unconsumed.isEmpty
7676
}, "maintain order")
7777
assert(xs == (xs intersect xs),
7878
"has the list as again intersection")

tests/run/predef-cycle.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Force {
2-
val t1 = new Thread {
2+
val t1 = new Thread {
33
override def run(): Unit = {
44
scala.`package`
55
}

tests/run/t3980.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ object A {
55
x
66
}
77
def run2: Unit = {
8-
lazy val y: Int = 2
9-
println(y)
10-
println(y)
8+
lazy val y: Int = 2
9+
println(y)
10+
println(y)
1111
}
1212
}
1313

1414
object Test {
1515
def main(args: Array[String]) = {
16-
A.run1
17-
A.run2
16+
A.run1
17+
A.run2
1818
}
1919
}

tests/run/t4317/S_3.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
object Test {
22
def main(args: Array[String]): Unit = {
33
val j = new J_2()
4-
println(j.bar1())
5-
println(j.bar2())
6-
println(j.bar3())
4+
println(j.bar1())
5+
println(j.bar2())
6+
println(j.bar3())
77
}
88
}

tests/run/t6443-by-name.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
object Test {
22

3-
def main(args: Array[String]): Unit = {
4-
def foo = {println("foo"); 0}
5-
lazyDep(X)(foo)
6-
}
3+
def main(args: Array[String]): Unit = {
4+
def foo = {println("foo"); 0}
5+
lazyDep(X)(foo)
6+
}
77

88
trait T {
9-
type U
9+
type U
1010
}
1111
object X extends T { type U = Int }
1212

13-
def lazyDep(t: T)(u: => t.U): Unit = {
14-
println("1")
15-
u
16-
u
17-
}
13+
def lazyDep(t: T)(u: => t.U): Unit = {
14+
println("1")
15+
u
16+
u
17+
}
1818
}

tests/run/t6443-varargs.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
object Test {
22

3-
def main(args: Array[String]): Unit = {
4-
def foo = {println("foo"); 0}
5-
lazyDep(X)(foo)
6-
}
3+
def main(args: Array[String]): Unit = {
4+
def foo = {println("foo"); 0}
5+
lazyDep(X)(foo)
6+
}
77

88
trait T {
9-
type U
9+
type U
1010
}
1111
object X extends T { type U = Int }
1212

13-
def lazyDep(t: T)(us: t.U*): Unit = {
14-
List(us: _*)
15-
}
13+
def lazyDep(t: T)(us: t.U*): Unit = {
14+
List(us: _*)
15+
}
1616
}

0 commit comments

Comments
 (0)