зеркало из https://github.com/mozilla/pluotsorbet.git
Use "th.check()" in the added StringBuffer tests.
This commit is contained in:
Родитель
7217c02efe
Коммит
3adde8cc87
20
LICENSE
20
LICENSE
|
@ -248,3 +248,23 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
tests/gnu/testlet/vm/StringBufferTest.java (additional tests): Apache
|
||||||
|
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
|
@ -539,7 +539,8 @@ Override.simple("java/lang/StringBuffer.delete.(II)Ljava/lang/StringBuffer;",
|
||||||
stringBufferDelete);
|
stringBufferDelete);
|
||||||
|
|
||||||
Override.simple("java/lang/StringBuffer.deleteCharAt.(I)Ljava/lang/StringBuffer;", function(index) {
|
Override.simple("java/lang/StringBuffer.deleteCharAt.(I)Ljava/lang/StringBuffer;", function(index) {
|
||||||
if (index < 0 || index >= this.count) {
|
if (index >= this.count) {
|
||||||
|
// stringBufferDelete handles the other boundary checks; this check is specific to deleteCharAt.
|
||||||
throw new JavaException("java/lang/StringIndexOutOfBoundsException");
|
throw new JavaException("java/lang/StringIndexOutOfBoundsException");
|
||||||
}
|
}
|
||||||
return stringBufferDelete.call(this, index, index + 1);
|
return stringBufferDelete.call(this, index, index + 1);
|
||||||
|
|
|
@ -36,7 +36,7 @@ casper.test.begin("unit tests", 5 + gfxTests.length, function(test) {
|
||||||
casper
|
casper
|
||||||
.start("http://localhost:8000/index.html")
|
.start("http://localhost:8000/index.html")
|
||||||
.waitForText("DONE", function() {
|
.waitForText("DONE", function() {
|
||||||
test.assertTextExists("DONE: 4912 pass, 0 fail, 168 known fail, 0 unknown pass", "run unit tests");
|
test.assertTextExists("DONE: 4936 pass, 0 fail, 168 known fail, 0 unknown pass", "run unit tests");
|
||||||
});
|
});
|
||||||
|
|
||||||
casper
|
casper
|
||||||
|
|
|
@ -28,12 +28,13 @@ import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
class StringBufferTest implements Testlet {
|
class StringBufferTest implements Testlet {
|
||||||
|
|
||||||
|
private TestHarness th;
|
||||||
public void test(TestHarness th) {
|
public void test(TestHarness th) {
|
||||||
|
this.th = th;
|
||||||
th.check(test1(), 0);
|
th.check(test1(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int test1() {
|
public int test1() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new StringBuffer(-1);
|
new StringBuffer(-1);
|
||||||
return 100;
|
return 100;
|
||||||
|
@ -51,7 +52,7 @@ class StringBufferTest implements Testlet {
|
||||||
if (! str1.toString().equals("")) {
|
if (! str1.toString().equals("")) {
|
||||||
return 130;
|
return 130;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer str2 = new StringBuffer("testing");
|
StringBuffer str2 = new StringBuffer("testing");
|
||||||
if (str2.length() != 7) {
|
if (str2.length() != 7) {
|
||||||
return 140;
|
return 140;
|
||||||
|
@ -75,7 +76,7 @@ class StringBufferTest implements Testlet {
|
||||||
if (! strbuf.append("hiii").toString().equals("hiii")) {
|
if (! strbuf.append("hiii").toString().equals("hiii")) {
|
||||||
return 190;
|
return 190;
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf = new StringBuffer(10);
|
strbuf = new StringBuffer(10);
|
||||||
if (strbuf.capacity() != 10) {
|
if (strbuf.capacity() != 10) {
|
||||||
return 200;
|
return 200;
|
||||||
|
@ -84,16 +85,16 @@ class StringBufferTest implements Testlet {
|
||||||
if (! str1.toString().equals("03041965")) {
|
if (! str1.toString().equals("03041965")) {
|
||||||
return 210;
|
return 210;
|
||||||
}
|
}
|
||||||
|
|
||||||
str1 = new StringBuffer();
|
str1 = new StringBuffer();
|
||||||
if (! str1.toString().equals("")) {
|
if (! str1.toString().equals("")) {
|
||||||
return 220;
|
return 220;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** capacity tests...
|
** capacity tests...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
str1 = new StringBuffer("");
|
str1 = new StringBuffer("");
|
||||||
str2 = new StringBuffer("pentiumpentiumpentium");
|
str2 = new StringBuffer("pentiumpentiumpentium");
|
||||||
if (str1.capacity() != 16) {
|
if (str1.capacity() != 16) {
|
||||||
|
@ -107,11 +108,11 @@ class StringBufferTest implements Testlet {
|
||||||
if (str1.capacity() != 34) {
|
if (str1.capacity() != 34) {
|
||||||
return 250;
|
return 250;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** setLength tests...
|
** setLength tests...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
str1 = new StringBuffer("ba");
|
str1 = new StringBuffer("ba");
|
||||||
try {
|
try {
|
||||||
str1.setLength(-1);
|
str1.setLength(-1);
|
||||||
|
@ -119,12 +120,12 @@ class StringBufferTest implements Testlet {
|
||||||
}
|
}
|
||||||
catch (IndexOutOfBoundsException e) {
|
catch (IndexOutOfBoundsException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
str1. setLength(4);
|
str1. setLength(4);
|
||||||
if (str1.length() != 4) {
|
if (str1.length() != 4) {
|
||||||
return 270;
|
return 270;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str1.charAt(0) != 'b') {
|
if (str1.charAt(0) != 'b') {
|
||||||
return 280;
|
return 280;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +156,7 @@ class StringBufferTest implements Testlet {
|
||||||
if (str1.charAt(3) != 'd') {
|
if (str1.charAt(3) != 'd') {
|
||||||
return 350;
|
return 350;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
str1.charAt(4);
|
str1.charAt(4);
|
||||||
return 360;
|
return 360;
|
||||||
|
@ -169,7 +170,7 @@ class StringBufferTest implements Testlet {
|
||||||
}
|
}
|
||||||
catch (IndexOutOfBoundsException e) {
|
catch (IndexOutOfBoundsException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** getChars tests...
|
** getChars tests...
|
||||||
*/
|
*/
|
||||||
|
@ -195,7 +196,7 @@ class StringBufferTest implements Testlet {
|
||||||
** Index out of bounds of StringBuffer - srcOffset
|
** Index out of bounds of StringBuffer - srcOffset
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
str1.getChars(4, 3, dst, 3);
|
str1.getChars(4, 3, dst, 3);
|
||||||
return 400;
|
return 400;
|
||||||
|
@ -203,7 +204,7 @@ class StringBufferTest implements Testlet {
|
||||||
catch (IndexOutOfBoundsException e) {
|
catch (IndexOutOfBoundsException e) {
|
||||||
/*
|
/*
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -265,10 +266,10 @@ class StringBufferTest implements Testlet {
|
||||||
/*
|
/*
|
||||||
** append tests...
|
** append tests...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
str1 = new StringBuffer();
|
str1 = new StringBuffer();
|
||||||
Object NULL = null;
|
Object NULL = null;
|
||||||
|
|
||||||
if (! str1.append(NULL).toString().equals("null")) {
|
if (! str1.append(NULL).toString().equals("null")) {
|
||||||
return 540;
|
return 540;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +298,7 @@ class StringBufferTest implements Testlet {
|
||||||
}
|
}
|
||||||
catch (NullPointerException e) {
|
catch (NullPointerException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] carr1 = {'h', 'i', 't', 'h', 'e', 'r'};
|
char[] carr1 = {'h', 'i', 't', 'h', 'e', 'r'};
|
||||||
str1 = new StringBuffer("!");
|
str1 = new StringBuffer("!");
|
||||||
str1 = str1.append(carr1);
|
str1 = str1.append(carr1);
|
||||||
|
@ -457,7 +458,7 @@ class StringBufferTest implements Testlet {
|
||||||
/*
|
/*
|
||||||
** setCharAt tests...
|
** setCharAt tests...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
str1 = new StringBuffer("1234567");
|
str1 = new StringBuffer("1234567");
|
||||||
try {
|
try {
|
||||||
str1.setCharAt(-1, 'A');
|
str1.setCharAt(-1, 'A');
|
||||||
|
@ -481,7 +482,7 @@ class StringBufferTest implements Testlet {
|
||||||
/*
|
/*
|
||||||
** deleteCharAt tests...
|
** deleteCharAt tests...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
str1 = new StringBuffer("123456789");
|
str1 = new StringBuffer("123456789");
|
||||||
try {
|
try {
|
||||||
str1.deleteCharAt(-1);
|
str1.deleteCharAt(-1);
|
||||||
|
@ -501,7 +502,7 @@ class StringBufferTest implements Testlet {
|
||||||
if (! str1.toString().equals("12346789")) {
|
if (! str1.toString().equals("12346789")) {
|
||||||
return 940;
|
return 940;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str1.length() != 8) {
|
if (str1.length() != 8) {
|
||||||
return 950;
|
return 950;
|
||||||
}
|
}
|
||||||
|
@ -539,37 +540,36 @@ class StringBufferTest implements Testlet {
|
||||||
StringBuffer obj = new StringBuffer();
|
StringBuffer obj = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
obj.getChars(0, 0, new char[0], -1);
|
obj.getChars(0, 0, new char[0], -1);
|
||||||
return 1080;
|
th.fail();
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
// expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer("abcde");
|
StringBuffer buffer = new StringBuffer("abcde");
|
||||||
try {
|
try {
|
||||||
buffer.setLength(-1);
|
buffer.setLength(-1);
|
||||||
return 1090;
|
th.fail();
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
// expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!"abcde".equals(buffer.toString())) { return 1091; }
|
th.check(buffer.toString(), "abcde");
|
||||||
buffer.setLength(1);
|
buffer.setLength(1);
|
||||||
buffer.append('f');
|
buffer.append('f');
|
||||||
System.out.println(buffer.toString());
|
th.check(buffer.toString(), "af");
|
||||||
if (!"af".equals(buffer.toString())) { return 1092; }
|
|
||||||
|
|
||||||
buffer = new StringBuffer("abcde");
|
buffer = new StringBuffer("abcde");
|
||||||
buffer.setLength(3);
|
buffer.setLength(3);
|
||||||
buffer.append('f');
|
buffer.append('f');
|
||||||
if (!"abcf".equals(buffer.toString())) { return 1093; }
|
th.check(buffer.toString(), "abcf");
|
||||||
|
|
||||||
buffer = new StringBuffer("abcde");
|
buffer = new StringBuffer("abcde");
|
||||||
buffer.setLength(2);
|
buffer.setLength(2);
|
||||||
try {
|
try {
|
||||||
buffer.charAt(3);
|
buffer.charAt(3);
|
||||||
return 1100;
|
th.fail();
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
// Expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
|
@ -577,67 +577,59 @@ class StringBufferTest implements Testlet {
|
||||||
buffer.setLength(2);
|
buffer.setLength(2);
|
||||||
buffer.setLength(5);
|
buffer.setLength(5);
|
||||||
for (int i = 2; i < 5; i++) {
|
for (int i = 2; i < 5; i++) {
|
||||||
if (buffer.charAt(i) != '\u0000') {
|
th.check('\u0000', buffer.charAt(i));
|
||||||
return 1101;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
buffer.append("abcdefg");
|
buffer.append("abcdefg");
|
||||||
buffer.delete(2, 4);
|
buffer.delete(2, 4);
|
||||||
buffer.setLength(7);
|
buffer.setLength(7);
|
||||||
if (buffer.charAt(0) != 'a') { return 1102; }
|
th.check(buffer.charAt(0), 'a');
|
||||||
if (buffer.charAt(1) != 'b') { return 1103; }
|
th.check(buffer.charAt(1), 'b');
|
||||||
if (buffer.charAt(2) != 'e') { return 1104; }
|
th.check(buffer.charAt(2), 'e');
|
||||||
if (buffer.charAt(3) != 'f') { return 1105; }
|
th.check(buffer.charAt(3), 'f');
|
||||||
if (buffer.charAt(4) != 'g') { return 1106; }
|
th.check(buffer.charAt(4), 'g');
|
||||||
for (int i = 5; i < 7; i++) {
|
for (int i = 5; i < 7; i++) {
|
||||||
if (buffer.charAt(i) != '\u0000') {
|
th.check('\u0000', buffer.charAt(i));
|
||||||
return 1107;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
buffer.append("abcdefg");
|
buffer.append("abcdefg");
|
||||||
buffer.setLength(5);
|
buffer.setLength(5);
|
||||||
buffer.setLength(7);
|
buffer.setLength(7);
|
||||||
for (int i = 5; i < 7; i++) {
|
for (int i = 5; i < 7; i++) {
|
||||||
if (buffer.charAt(i) != '\u0000') {
|
th.check('\u0000', buffer.charAt(i));
|
||||||
return 1108;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
if (!"".equals(buffer.toString())) {
|
th.check(buffer.toString(), "");
|
||||||
return 1109;
|
|
||||||
}
|
|
||||||
buffer.append("abcde");
|
buffer.append("abcde");
|
||||||
if (!"abcde".equals(buffer.toString())) { return 1110; }
|
th.check(buffer.toString(), "abcde");
|
||||||
buffer.setLength(5);
|
buffer.setLength(5);
|
||||||
buffer.append("fghij");
|
buffer.append("fghij");
|
||||||
if (!"abcdefghij".equals(buffer.toString())) { return 1111; }
|
th.check(buffer.toString(), "abcdefghij");
|
||||||
|
|
||||||
obj = new StringBuffer();
|
obj = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
obj.append(new char[0], -1, -1);
|
obj.append(new char[0], -1, -1);
|
||||||
return 1112;
|
th.fail();
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
// expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = new StringBuffer();
|
obj = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
obj.append((char[]) null, -1, -1);
|
obj.append((char[]) null, -1, -1);
|
||||||
return 1120;
|
th.fail();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = new StringBuffer();
|
obj = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
obj.insert(-1, ' ');
|
obj.insert(-1, ' ');
|
||||||
return 1130;
|
th.fail();
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
// expected
|
th.pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче