Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/String/Lines.java
41149 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
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
* @summary Basic lines functionality
27
* @bug 8200380
28
* @run main/othervm Lines
29
*/
30
31
import java.util.Iterator;
32
import java.util.stream.Stream;
33
import java.io.BufferedReader;
34
import java.io.StringReader;
35
36
public class Lines {
37
public static void main(String... arg) {
38
testLines();
39
}
40
41
/*
42
* Test with strings
43
*/
44
static void testLines() {
45
testString("");
46
testString(" ");
47
testString("\n");
48
testString("\n\n\n");
49
testString("\r\r\r");
50
testString("\r\n\r\n\r\n");
51
testString("\n\r\r\n");
52
testString("abc\ndef\nghi\n");
53
testString("abc\ndef\nghi");
54
testString("abc\rdef\rghi\r");
55
testString("abc\rdef\rghi");
56
testString("abc\r\ndef\r\nghi\r\n");
57
testString("abc\r\ndef\r\nghi");
58
59
testString("\2022");
60
testString("\2022\n");
61
testString("\2022\n\2022\n\2022\n");
62
testString("\2022\r\2022\r\2022\r");
63
testString("\2022\r\n\2022\r\n\2022\r\n");
64
testString("\2022\n\2022\r\2022\r\n");
65
testString("abc\2022\ndef\2022\nghi\2022\n");
66
testString("abc\2022\ndef\2022\nghi\2022");
67
testString("abc\2022\rdef\2022\rghi\2022\r");
68
testString("abc\2022\rdef\2022\rghi\2022");
69
testString("abc\2022\r\ndef\2022\r\nghi\2022\r\n");
70
testString("abc\2022\r\ndef\2022\r\nghi\2022");
71
testString("\2022\n\n\n");
72
}
73
74
static void testString(String string) {
75
Stream<String> lines = string.lines();
76
Stream<String> brLines = new BufferedReader(new StringReader(string)).lines();
77
78
Iterator<String> iterator = lines.iterator();
79
Iterator<String> brIterator = brLines.iterator();
80
int count = 0;
81
82
while (iterator.hasNext() && brIterator.hasNext()) {
83
count++;
84
String line = iterator.next();
85
String brLine = brIterator.next();
86
87
if (!line.equals(brLine)) {
88
String replace = string.replaceAll("\n", "\\n").replaceAll("\r", "\\r");
89
System.err.format("Mismatch at line %d of \"%s\"%n", count, replace);
90
throw new RuntimeException();
91
}
92
}
93
94
if (iterator.hasNext() || brIterator.hasNext()) {
95
System.err.format("Mismatch after line %d of \"%s\"%n", count, string);
96
throw new RuntimeException();
97
}
98
}
99
}
100
101