aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pretty/resource/after/Switch17.java31
-rw-r--r--test/pretty/resource/before/Switch17.java32
2 files changed, 63 insertions, 0 deletions
diff --git a/test/pretty/resource/after/Switch17.java b/test/pretty/resource/after/Switch17.java
new file mode 100644
index 00000000..038f2cd9
--- /dev/null
+++ b/test/pretty/resource/after/Switch17.java
@@ -0,0 +1,31 @@
+public class Switch17 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s && s.length() > 1 -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/before/Switch17.java b/test/pretty/resource/before/Switch17.java
new file mode 100644
index 00000000..17754e82
--- /dev/null
+++ b/test/pretty/resource/before/Switch17.java
@@ -0,0 +1,32 @@
+// version 17:
+public class Switch17 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s && s.length() > 1 -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+}