|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat; |
18 | 18 | import static com.google.common.truth.Truth.assertWithMessage; |
| 19 | +import static com.google.common.truth.TruthJUnit.assume; |
19 | 20 | import static java.nio.charset.StandardCharsets.UTF_8; |
20 | 21 | import static org.junit.Assert.assertThrows; |
21 | 22 |
|
| 23 | +import com.google.common.base.Enums; |
22 | 24 | import com.google.common.io.CharStreams; |
23 | 25 | import com.google.googlejavaformat.java.JavaFormatterOptions.Style; |
24 | 26 | import java.io.ByteArrayInputStream; |
|
29 | 31 | import java.io.StringWriter; |
30 | 32 | import java.nio.file.Files; |
31 | 33 | import java.nio.file.Path; |
| 34 | +import javax.lang.model.element.Modifier; |
32 | 35 | import org.junit.Rule; |
33 | 36 | import org.junit.Test; |
34 | 37 | import org.junit.rules.TemporaryFolder; |
@@ -869,4 +872,38 @@ public void maxLineLengthOutOfRange() { |
869 | 872 |
|
870 | 873 | assertThat(Style.builder().maxLineLength(999).build().maxLineLength()).isEqualTo(999); |
871 | 874 | } |
| 875 | + |
| 876 | + @Test |
| 877 | + public void valueClassAndRecord() throws Exception { |
| 878 | + assume().that(Enums.getIfPresent(Modifier.class, "VALUE").isPresent()).isTrue(); |
| 879 | + String input = |
| 880 | + """ |
| 881 | + value final public class PointValueClass { |
| 882 | + final int x; |
| 883 | + final int y; |
| 884 | +
|
| 885 | + PointValueClass(int x, int y) { |
| 886 | + this.x = x; |
| 887 | + this.y = y; |
| 888 | + } |
| 889 | + } |
| 890 | +
|
| 891 | + value public record PointValueRecord(int x, int y) {} |
| 892 | + """; |
| 893 | + String expected = |
| 894 | + """ |
| 895 | + public final value class PointValueClass { |
| 896 | + final int x; |
| 897 | + final int y; |
| 898 | +
|
| 899 | + PointValueClass(int x, int y) { |
| 900 | + this.x = x; |
| 901 | + this.y = y; |
| 902 | + } |
| 903 | + } |
| 904 | +
|
| 905 | + public value record PointValueRecord(int x, int y) {} |
| 906 | + """; |
| 907 | + assertThat(new Formatter().formatSource(input)).isEqualTo(expected); |
| 908 | + } |
872 | 909 | } |
0 commit comments