< prev index next >

test/jdk/java/lang/String/AlignIndent.java

Print this page
rev 53050 : 8215493: String::indent inconsistency with blank lines
Reviewed-by: rriggs, smarks


 122                     }
 123                 }
 124             }
 125         }
 126     }
 127 
 128     /*
 129      * Test String#indent(int n) functionality.
 130      */
 131     static void test3() {
 132         for (int adjust : new int[] {-8, -7, -4, -3, -2, -1, 0, 1, 2, 3, 4, 7, 8}) {
 133             for (String prefix : ENDS) {
 134                 for (String suffix : ENDS) {
 135                     for (String middle : MIDDLES) {
 136                         String input = prefix + "   abc   \n" + middle + "\n   def   \n" + suffix;
 137                         String output = input.indent(adjust);
 138 
 139                         Stream<String> stream = input.lines();
 140                         if (adjust > 0) {
 141                             final String spaces = " ".repeat(adjust);
 142                             stream = stream.map(s -> s.isBlank() ? s : spaces + s);
 143                         } else if (adjust < 0) {
 144                             stream = stream.map(s -> s.substring(Math.min(-adjust, indexOfNonWhitespace(s))));
 145                         }
 146                         String expected = stream.collect(Collectors.joining("\n", "", "\n"));
 147 
 148                         if (!output.equals(expected)) {
 149                             report("String::indent(int n)",
 150                                     "Result indentation not as expected", expected, output);
 151                         }
 152                     }
 153                 }
 154             }
 155         }
 156     }
 157 
 158     /*
 159      * JDK-8212694: Using Raw String Literals with align() and Integer.MIN_VALUE causes out of memory error
 160      */
 161     static void test4() {
 162         try {




 122                     }
 123                 }
 124             }
 125         }
 126     }
 127 
 128     /*
 129      * Test String#indent(int n) functionality.
 130      */
 131     static void test3() {
 132         for (int adjust : new int[] {-8, -7, -4, -3, -2, -1, 0, 1, 2, 3, 4, 7, 8}) {
 133             for (String prefix : ENDS) {
 134                 for (String suffix : ENDS) {
 135                     for (String middle : MIDDLES) {
 136                         String input = prefix + "   abc   \n" + middle + "\n   def   \n" + suffix;
 137                         String output = input.indent(adjust);
 138 
 139                         Stream<String> stream = input.lines();
 140                         if (adjust > 0) {
 141                             final String spaces = " ".repeat(adjust);
 142                             stream = stream.map(s -> spaces + s);
 143                         } else if (adjust < 0) {
 144                             stream = stream.map(s -> s.substring(Math.min(-adjust, indexOfNonWhitespace(s))));
 145                         }
 146                         String expected = stream.collect(Collectors.joining("\n", "", "\n"));
 147 
 148                         if (!output.equals(expected)) {
 149                             report("String::indent(int n)",
 150                                     "Result indentation not as expected", expected, output);
 151                         }
 152                     }
 153                 }
 154             }
 155         }
 156     }
 157 
 158     /*
 159      * JDK-8212694: Using Raw String Literals with align() and Integer.MIN_VALUE causes out of memory error
 160      */
 161     static void test4() {
 162         try {


< prev index next >