Skip to content

Commit acbbc94

Browse files
committed
Add indent rewrite tests
1 parent b618148 commit acbbc94

12 files changed

+710
-3
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ class CompilationTests {
8282
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
8383
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
8484
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
85-
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
86-
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite")),
87-
compileFile("tests/rewrites/i11895.scala", defaultOptions.and("-indent", "-rewrite")),
85+
compileFile("tests/rewrites/i8982.scala", indentRewrite),
86+
compileFile("tests/rewrites/i9632.scala", indentRewrite),
87+
compileFile("tests/rewrites/i11895.scala", indentRewrite),
88+
compileFile("tests/rewrites/indent-rewrite.scala", indentRewrite),
89+
compileFile("tests/rewrites/indent-comments.scala", indentRewrite),
90+
compileFile("tests/rewrites/indent-mix-tab-space.scala", indentRewrite),
91+
compileFile("tests/rewrites/indent-3-spaces.scala", indentRewrite),
92+
compileFile("tests/rewrites/indent-mix-brace.scala", indentRewrite),
8893
compileFile("tests/rewrites/i12340.scala", unindentOptions.and("-rewrite")),
8994
compileFile("tests/rewrites/i17187.scala", unindentOptions.and("-rewrite")),
9095
compileFile("tests/rewrites/i17399.scala", unindentOptions.and("-rewrite")),

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ object TestConfiguration {
6565

6666
val commonOptions = Array("-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions
6767
val defaultOptions = TestFlags(basicClasspath, commonOptions)
68+
val indentRewrite = defaultOptions.and("-rewrite")
6869
val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions)
6970
val withCompilerOptions =
7071
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)

tests/rewrites/indent-3-spaces.check

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Rewrite to indent, keeping 3 spaces as indentation
2+
3+
def m1 =
4+
def m2 =
5+
"" +
6+
"" +
7+
""
8+
m2
9+
10+
def m4 =
11+
def m5 =
12+
def m6 =
13+
val x = ""
14+
x
15+
.apply(0)
16+
.toString
17+
m6
18+
.toString
19+
m5 +
20+
m5
21+
.toString

tests/rewrites/indent-3-spaces.scala

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Rewrite to indent, keeping 3 spaces as indentation
2+
3+
def m1 = {
4+
def m2 = {
5+
"" +
6+
"" +
7+
""
8+
}
9+
m2
10+
}
11+
12+
def m4 = {
13+
def m5 = {
14+
def m6 = {
15+
val x = ""
16+
x
17+
.apply(0)
18+
.toString
19+
}
20+
m6
21+
.toString
22+
}
23+
m5 +
24+
m5
25+
.toString
26+
}

tests/rewrites/indent-comments.check

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Rewriting to indent should preserve comments
2+
class A: /* 1 */ /* 2 */
3+
def m1(b: Boolean) = /* 3 */ /* 4 */
4+
val x = if (b)
5+
/* 5 */
6+
"true"
7+
/* 6 */
8+
else
9+
/* 7 */
10+
"false"
11+
/* 8 */
12+
/* 9 */ x.toBoolean
13+
/* 10 */ /* 11 */
14+
/* 12 */def m2 = // 12
15+
m1:// 14
16+
/* 15 */// 16
17+
true
18+
/* 17 */// 18
19+
// because of the missing indent before {
20+
// the scanner inserts a new line between || and {
21+
// cannot rewrite to indentation without messing the comments up
22+
true ||// 19
23+
/* 20 */{
24+
false
25+
}// 21

tests/rewrites/indent-comments.scala

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Rewriting to indent should preserve comments
2+
class A /* 1 */ { /* 2 */
3+
def m1(b: Boolean) = /* 3 */ { /* 4 */
4+
val x = if (b)
5+
/* 5 */ {
6+
"true"
7+
} /* 6 */
8+
else
9+
{ /* 7 */
10+
"false"
11+
/* 8 */ }
12+
/* 9 */ x.toBoolean
13+
/* 10 */ } /* 11 */
14+
/* 12 */def m2 = {// 12
15+
m1// 14
16+
/* 15 */{// 16
17+
true
18+
/* 17 */}// 18
19+
// because of the missing indent before {
20+
// the scanner inserts a new line between || and {
21+
// cannot rewrite to indentation without messing the comments up
22+
true ||// 19
23+
/* 20 */{
24+
false
25+
}// 21
26+
}
27+
}

tests/rewrites/indent-mix-brace.check

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A mix of nested in-brace regions and indented regions
2+
3+
class A:
4+
def m1 =
5+
""
6+
7+
def m2 =
8+
def m3 =
9+
val x = ""
10+
x
11+
m3
12+
13+
class B:
14+
def foo =
15+
def bar =
16+
""
17+
bar

tests/rewrites/indent-mix-brace.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A mix of nested in-brace regions and indented regions
2+
3+
class A:
4+
def m1 = {
5+
""
6+
}
7+
8+
def m2 = {
9+
def m3 =
10+
val x = ""
11+
x
12+
m3
13+
}
14+
15+
class B {
16+
def foo =
17+
def bar = {
18+
""
19+
}
20+
bar
21+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Contains an ugly but valid mix of spaces and tabs
2+
// Rewrite to significant indentation syntax
3+
4+
def m1 =
5+
def m2 =
6+
"" +
7+
"" +
8+
""
9+
m2
10+
11+
def m4 =
12+
def m5 =
13+
def m6 =
14+
val x = ""
15+
x
16+
.apply(0)
17+
.toString
18+
m6
19+
.toString
20+
m5 +
21+
m5
22+
.toString
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Contains an ugly but valid mix of spaces and tabs
2+
// Rewrite to significant indentation syntax
3+
4+
def m1 = {
5+
def m2 = {
6+
"" +
7+
"" +
8+
""
9+
}
10+
m2
11+
}
12+
13+
def m4 = {
14+
def m5 = {
15+
def m6 = {
16+
val x = ""
17+
x
18+
.apply(0)
19+
.toString
20+
}
21+
m6
22+
.toString
23+
}
24+
m5 +
25+
m5
26+
.toString
27+
}

0 commit comments

Comments
 (0)