Skip to content

Commit 3fee48a

Browse files
committed
Validate that we can inline switch expressions
1 parent 49c3ddf commit 3fee48a

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/test/java/org/openrewrite/staticanalysis/InlineVariableTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,46 @@ List<String> testLambda(List<String> names) {
103103
);
104104
}
105105

106+
@Test
107+
void inlineSwitch() {
108+
rewriteRun(
109+
//language=java
110+
java(
111+
"""
112+
import java.util.List;
113+
import java.util.stream.Collectors;
114+
115+
class Test {
116+
String test(int n) {
117+
String s = switch (n) {
118+
case 1 -> "one";
119+
case 2 -> "two";
120+
case 3 -> "three";
121+
default -> "unknown";
122+
};
123+
return s;
124+
}
125+
}
126+
""",
127+
"""
128+
import java.util.List;
129+
import java.util.stream.Collectors;
130+
131+
class Test {
132+
String test(int n) {
133+
return switch (n) {
134+
case 1 -> "one";
135+
case 2 -> "two";
136+
case 3 -> "three";
137+
default -> "unknown";
138+
};
139+
}
140+
}
141+
"""
142+
)
143+
);
144+
}
145+
106146
@SuppressWarnings("UnnecessaryLocalVariable")
107147
@Test
108148
void preserveComments() {

0 commit comments

Comments
 (0)