diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2022-08-26 00:53:21 +0200 |
---|---|---|
committer | Rawi01 <Rawi01@users.noreply.github.com> | 2022-08-26 00:53:21 +0200 |
commit | 957adfae2ece1fe8a469976143ae7c8db8e67686 (patch) | |
tree | f3afb5c9a4a3f221788b552f090f55decc616887 /test | |
parent | 646723f6d30404b2974af4fbefad5d8843460fea (diff) | |
download | lombok-957adfae2ece1fe8a469976143ae7c8db8e67686.tar.gz lombok-957adfae2ece1fe8a469976143ae7c8db8e67686.tar.bz2 lombok-957adfae2ece1fe8a469976143ae7c8db8e67686.zip |
[jdk19] Add support for new guard pattern
Diffstat (limited to 'test')
-rw-r--r-- | test/pretty/resource/after/Switch19.java | 32 | ||||
-rw-r--r-- | test/pretty/resource/before/Switch17.java | 2 | ||||
-rw-r--r-- | test/pretty/resource/before/Switch19.java | 33 |
3 files changed, 66 insertions, 1 deletions
diff --git a/test/pretty/resource/after/Switch19.java b/test/pretty/resource/after/Switch19.java new file mode 100644 index 00000000..5947830b --- /dev/null +++ b/test/pretty/resource/after/Switch19.java @@ -0,0 +1,32 @@ +public class Switch19 { + 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 when s.length() > 1 -> s; + case String s -> s; + default -> o.toString(); + }; + } + + String switchParenthesizedPattern(Object o) { + return switch (o) { + case (String s) -> s; + default -> o.toString(); + }; + } +} diff --git a/test/pretty/resource/before/Switch17.java b/test/pretty/resource/before/Switch17.java index 17754e82..42a8f181 100644 --- a/test/pretty/resource/before/Switch17.java +++ b/test/pretty/resource/before/Switch17.java @@ -1,4 +1,4 @@ -// version 17: +// version 17:18 public class Switch17 { String switchPatternMatching(Object o) { return switch (o) { diff --git a/test/pretty/resource/before/Switch19.java b/test/pretty/resource/before/Switch19.java new file mode 100644 index 00000000..05b27928 --- /dev/null +++ b/test/pretty/resource/before/Switch19.java @@ -0,0 +1,33 @@ +// version 19: +public class Switch19 { + 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 when s.length() > 1 -> s; + case String s -> s; + default -> o.toString(); + }; + } + + String switchParenthesizedPattern(Object o) { + return switch (o) { + case (String s) -> s; + default -> o.toString(); + }; + } +} |