< prev index next >

test/java/lang/String/Split.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6840246 6559590
  27  * @summary test String.split()

  28  */
  29 import java.util.Arrays;
  30 import java.util.Random;
  31 import java.util.regex.*;
  32 
  33 public class Split {
  34 
  35     public static void main(String[] args) throws Exception {
  36         String source = "0123456789";
  37 
  38         for (int limit=-2; limit<3; limit++) {
  39             for (int x=0; x<10; x++) {
  40                 String[] result = source.split(Integer.toString(x), limit);
  41                 int expectedLength = limit < 1 ? 2 : limit;
  42 
  43                 if ((limit == 0) && (x == 9)) {
  44                     // expected dropping of ""
  45                     if (result.length != 1)
  46                         throw new RuntimeException("String.split failure 1");
  47                     if (!result[0].equals("012345678")) {




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6840246 6559590
  27  * @summary test String.split()
  28  * @key randomness
  29  */
  30 import java.util.Arrays;
  31 import java.util.Random;
  32 import java.util.regex.*;
  33 
  34 public class Split {
  35 
  36     public static void main(String[] args) throws Exception {
  37         String source = "0123456789";
  38 
  39         for (int limit=-2; limit<3; limit++) {
  40             for (int x=0; x<10; x++) {
  41                 String[] result = source.split(Integer.toString(x), limit);
  42                 int expectedLength = limit < 1 ? 2 : limit;
  43 
  44                 if ((limit == 0) && (x == 9)) {
  45                     // expected dropping of ""
  46                     if (result.length != 1)
  47                         throw new RuntimeException("String.split failure 1");
  48                     if (!result[0].equals("012345678")) {


< prev index next >