mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 11:05:28 -04:00
explain position information numbers in syntax exception
This commit is contained in:
parent
f1c9d0787b
commit
d69d5e284b
@ -520,11 +520,11 @@ public class JSONTokener {
|
||||
/**
|
||||
* Make a printable string of this JSONTokener.
|
||||
*
|
||||
* @return " at {index} [character {character} line {line}]"
|
||||
* @return " at index {index} [character number {character} in line {line}]"
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return " at " + this.index + " [character " + this.character + " line " +
|
||||
return " at index " + this.index + " [character number " + this.character + " in line " +
|
||||
this.line + "]";
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class CDLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Missing close quote '\"'. at 12 [character 0 line 2]",
|
||||
"Missing close quote '\"'. at index 12 [character number 0 in line 2]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ public class CDLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Missing close quote '\"'. at 22 [character 11 line 2]",
|
||||
"Missing close quote '\"'. at index 22 [character number 11 in line 2]",
|
||||
e.getMessage());
|
||||
|
||||
}
|
||||
@ -101,7 +101,7 @@ public class CDLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Bad character 'o' (111). at 2 [character 3 line 1]",
|
||||
"Bad character 'o' (111). at index 2 [character number 3 in line 1]",
|
||||
e.getMessage());
|
||||
|
||||
}
|
||||
@ -119,7 +119,7 @@ public class CDLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Missing close quote '\"'. at 26 [character 15 line 2]",
|
||||
"Missing close quote '\"'. at index 26 [character number 15 in line 2]",
|
||||
e.getMessage());
|
||||
|
||||
}
|
||||
@ -170,7 +170,7 @@ public class CDLTest {
|
||||
} catch (JSONException e) {
|
||||
//System.out.println("Message" + e.getMessage());
|
||||
assertEquals("Expecting an exception message",
|
||||
"Bad character 'V' (86). at 20 [character 9 line 2]",
|
||||
"Bad character 'V' (86). at index 20 [character number 9 in line 2]",
|
||||
e.getMessage());
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class CookieListTest {
|
||||
* Not sure of the missing char, but full string compare fails
|
||||
*/
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
|
||||
"Expected '=' and instead saw '' at index 25 [character number 26 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class CookieTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
|
||||
"Expected '=' and instead saw '' at index 25 [character number 26 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class JSONArrayTest {
|
||||
assertNull("Should throw an exception", new JSONArray(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expected an exception message",
|
||||
"A JSONArray text must start with '[' at 0 [character 1 line 1]",
|
||||
"A JSONArray text must start with '[' at index 0 [character number 1 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -142,7 +142,7 @@ public class JSONArrayTest {
|
||||
assertNull("Should throw an exception", new JSONArray("["));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expected an exception message",
|
||||
"Expected a ',' or ']' at 1 [character 2 line 1]",
|
||||
"Expected a ',' or ']' at index 1 [character number 2 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ public class JSONArrayTest {
|
||||
assertNull("Should throw an exception", new JSONArray("[\"test\""));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expected an exception message",
|
||||
"Expected a ',' or ']' at 7 [character 8 line 1]",
|
||||
"Expected a ',' or ']' at index 7 [character number 8 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -172,7 +172,7 @@ public class JSONArrayTest {
|
||||
assertNull("Should throw an exception", new JSONArray("[\"test\","));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expected an exception message",
|
||||
"Expected a ',' or ']' at 8 [character 9 line 1]",
|
||||
"Expected a ',' or ']' at index 8 [character number 9 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Bad XML at 0 [character 1 line 1]",
|
||||
"Bad XML at index 0 [character number 1 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -102,7 +102,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Bad XML at 23 [character 24 line 1]",
|
||||
"Bad XML at index 23 [character number 24 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -205,7 +205,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped tag at 176 [character 14 line 4]",
|
||||
"Misshaped tag at index 176 [character number 14 in line 4]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -230,7 +230,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 215 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 215 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -260,7 +260,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 214 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 214 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -290,7 +290,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misplaced '<' at 194 [character 5 line 6]",
|
||||
"Misplaced '<' at index 194 [character number 5 in line 6]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -350,7 +350,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misplaced '<' at 206 [character 1 line 7]",
|
||||
"Misplaced '<' at index 206 [character number 1 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -380,7 +380,7 @@ public class JSONMLTest {
|
||||
fail("Expecting an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected 'CDATA[' at 204 [character 11 line 5]",
|
||||
"Expected 'CDATA[' at index 204 [character number 11 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -682,7 +682,7 @@ public class JSONMLTest {
|
||||
"<address>\n"+
|
||||
"<!-- <!--[CDATA[ this is -- <another> comment ]] -->\n"+
|
||||
"<name>Joe Tester</name>\n"+
|
||||
"<!-- this is a - multi line \n"+
|
||||
"<!-- this is a - multi in line \n"+
|
||||
"comment -->\n"+
|
||||
"<street>Baker street 5</street>\n"+
|
||||
"</address>\n"+
|
||||
@ -815,7 +815,7 @@ public class JSONMLTest {
|
||||
fail("Exception expected for invalid JSON.");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Exception string did not match: ",
|
||||
"Unterminated string at 271 [character 272 line 1]",
|
||||
"Unterminated string at index 271 [character number 272 in line 1]",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
@ -829,7 +829,7 @@ public class JSONMLTest {
|
||||
fail("Exception expected for invalid JSON.");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Exception string did not match: ",
|
||||
"Unterminated string at 242 [character 238 line 2]",
|
||||
"Unterminated string at index 242 [character number 238 in line 2]",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -2202,7 +2202,7 @@ public class JSONObjectTest {
|
||||
fail("JSONException should be thrown");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Unterminated string. " + "Character with int code 0" +
|
||||
" is not allowed within a quoted string. at 8 [character 9 line 1]", ex.getMessage());
|
||||
" is not allowed within a quoted string. at index 8 [character number 9 in line 1]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2216,7 +2216,7 @@ public class JSONObjectTest {
|
||||
fail("JSONException should be thrown");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Unterminated string. " + "Character with int code " + (int) c +
|
||||
" is not allowed within a quoted string. at 9 [character 0 line 2]", ex.getMessage());
|
||||
" is not allowed within a quoted string. at index 9 [character number 0 in line 2]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2230,7 +2230,7 @@ public class JSONObjectTest {
|
||||
fail("JSONException should be thrown");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Illegal escape. \\u must be followed by a 4 digit hexadecimal number. " +
|
||||
"\\123x is not valid. at 14 [character 15 line 1]", ex.getMessage());
|
||||
"\\123x is not valid. at index 14 [character number 15 in line 1]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2243,7 +2243,7 @@ public class JSONObjectTest {
|
||||
fail("JSONException should be thrown");
|
||||
} catch (JSONException ex) {
|
||||
assertEquals("Illegal escape. Escape sequence " + c + " is not valid." +
|
||||
" at 10 [character 11 line 1]", ex.getMessage());
|
||||
" at index 10 [character number 11 in line 1]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2259,7 +2259,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"A JSONObject text must begin with '{' at 1 [character 2 line 1]",
|
||||
"A JSONObject text must begin with '{' at index 1 [character number 2 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2268,7 +2268,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"A JSONObject text must end with '}' at 1 [character 2 line 1]",
|
||||
"A JSONObject text must end with '}' at index 1 [character number 2 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2277,7 +2277,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected a ':' after a key at 10 [character 11 line 1]",
|
||||
"Expected a ':' after a key at index 10 [character number 11 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2286,7 +2286,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected a ',' or '}' at 15 [character 16 line 1]",
|
||||
"Expected a ',' or '}' at index 15 [character number 16 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2295,7 +2295,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Missing value at 1 [character 2 line 1]",
|
||||
"Missing value at index 1 [character number 2 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2304,7 +2304,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Missing value at 9 [character 10 line 1]",
|
||||
"Missing value at index 9 [character number 10 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2313,7 +2313,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected a ':' after a key at 5 [character 6 line 1]",
|
||||
"Expected a ':' after a key at index 5 [character number 6 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2322,7 +2322,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected a ':' after a key at 5 [character 6 line 1]",
|
||||
"Expected a ':' after a key at index 5 [character number 6 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2331,7 +2331,7 @@ public class JSONObjectTest {
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"A JSONObject text must end with '}' at 15 [character 16 line 1]",
|
||||
"A JSONObject text must end with '}' at index 15 [character number 16 in line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2412,7 +2412,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr03\" at 90 [character 13 line 5]",
|
||||
"Duplicate key \"attr03\" at index 90 [character number 13 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2431,7 +2431,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr03\" at 90 [character 13 line 5]",
|
||||
"Duplicate key \"attr03\" at index 90 [character number 13 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2452,7 +2452,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr03\" at 90 [character 13 line 5]",
|
||||
"Duplicate key \"attr03\" at index 90 [character number 13 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2472,7 +2472,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr04-03\" at 215 [character 20 line 9]",
|
||||
"Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2496,7 +2496,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr04-03\" at 215 [character 20 line 9]",
|
||||
"Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2522,7 +2522,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr04-03\" at 215 [character 20 line 9]",
|
||||
"Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2541,7 +2541,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr01\" at 124 [character 17 line 8]",
|
||||
"Duplicate key \"attr01\" at index 124 [character number 17 in line 8]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
@ -2566,7 +2566,7 @@ public class JSONObjectTest {
|
||||
fail("Expected an exception");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an expection message",
|
||||
"Duplicate key \"attr02-01\" at 269 [character 24 line 13]",
|
||||
"Duplicate key \"attr02-01\" at index 269 [character number 24 in line 13]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ public class JSONTokenerTest {
|
||||
|
||||
/**
|
||||
* Verify that next and back are working properly and tracking the correct positions
|
||||
* with different new line combinations.
|
||||
* with different new in line combinations.
|
||||
*/
|
||||
@Test
|
||||
public void testNextBackComboWithNewLines() {
|
||||
@ -241,74 +241,74 @@ public class JSONTokenerTest {
|
||||
// ^ ^ ^ ^
|
||||
// index positions 0 8 16 36
|
||||
final JSONTokener tokener = new JSONTokener(testString);
|
||||
assertEquals(" at 0 [character 1 line 1]", tokener.toString());
|
||||
assertEquals(" at index 0 [character number 1 in line 1]", tokener.toString());
|
||||
assertEquals('t',tokener.next());
|
||||
assertEquals(" at 1 [character 2 line 1]", tokener.toString());
|
||||
assertEquals(" at index 1 [character number 2 in line 1]", tokener.toString());
|
||||
tokener.skipTo('\n');
|
||||
assertEquals("skipTo() improperly modifying indexes"," at 7 [character 8 line 1]", tokener.toString());
|
||||
assertEquals("skipTo() improperly modifying indexes"," at index 7 [character number 8 in line 1]", tokener.toString());
|
||||
assertEquals('\n',tokener.next());
|
||||
assertEquals(" at 8 [character 0 line 2]", tokener.toString());
|
||||
assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString());
|
||||
assertEquals('A',tokener.next());
|
||||
assertEquals(" at 9 [character 1 line 2]", tokener.toString());
|
||||
assertEquals(" at index 9 [character number 1 in line 2]", tokener.toString());
|
||||
tokener.back();
|
||||
assertEquals(" at 8 [character 0 line 2]", tokener.toString());
|
||||
assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString());
|
||||
tokener.skipTo('\r');
|
||||
assertEquals("skipTo() improperly modifying indexes"," at 14 [character 6 line 2]", tokener.toString());
|
||||
// verify \r\n combo doesn't increment the line twice
|
||||
assertEquals("skipTo() improperly modifying indexes"," at index 14 [character number 6 in line 2]", tokener.toString());
|
||||
// verify \r\n combo doesn't increment the in line twice
|
||||
assertEquals('\r', tokener.next());
|
||||
assertEquals(" at 15 [character 0 line 3]", tokener.toString());
|
||||
assertEquals(" at index 15 [character number 0 in line 3]", tokener.toString());
|
||||
assertEquals('\n', tokener.next());
|
||||
assertEquals(" at 16 [character 0 line 3]", tokener.toString());
|
||||
// verify stepping back after reading the \n of an \r\n combo doesn't increment the line incorrectly
|
||||
assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString());
|
||||
// verify stepping back after reading the \n of an \r\n combo doesn't increment the in line incorrectly
|
||||
tokener.back();
|
||||
assertEquals(" at 15 [character 6 line 2]", tokener.toString());
|
||||
assertEquals(" at index 15 [character number 6 in line 2]", tokener.toString());
|
||||
assertEquals('\n', tokener.next());
|
||||
assertEquals(" at 16 [character 0 line 3]", tokener.toString());
|
||||
assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString());
|
||||
assertEquals('W', tokener.next());
|
||||
assertEquals(" at 17 [character 1 line 3]", tokener.toString());
|
||||
assertEquals(" at index 17 [character number 1 in line 3]", tokener.toString());
|
||||
assertEquals('i', tokener.next());
|
||||
assertEquals(" at 18 [character 2 line 3]", tokener.toString());
|
||||
assertEquals(" at index 18 [character number 2 in line 3]", tokener.toString());
|
||||
tokener.skipTo('\r');
|
||||
assertEquals("skipTo() improperly modifying indexes"," at 35 [character 19 line 3]", tokener.toString());
|
||||
assertEquals("skipTo() improperly modifying indexes"," at index 35 [character number 19 in line 3]", tokener.toString());
|
||||
assertEquals('\r', tokener.next());
|
||||
assertEquals(" at 36 [character 0 line 4]", tokener.toString());
|
||||
assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString());
|
||||
tokener.back();
|
||||
assertEquals(" at 35 [character 19 line 3]", tokener.toString());
|
||||
assertEquals(" at index 35 [character number 19 in line 3]", tokener.toString());
|
||||
assertEquals('\r', tokener.next());
|
||||
assertEquals(" at 36 [character 0 line 4]", tokener.toString());
|
||||
assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString());
|
||||
assertEquals('N', tokener.next());
|
||||
assertEquals(" at 37 [character 1 line 4]", tokener.toString());
|
||||
assertEquals(" at index 37 [character number 1 in line 4]", tokener.toString());
|
||||
|
||||
// verify we get the same data just walking though, no calls to back
|
||||
final JSONTokener t2 = new JSONTokener(testString);
|
||||
for(int i=0; i<7; i++) {
|
||||
assertTrue(t2.toString().startsWith(" at " + i + " "));
|
||||
assertTrue(t2.toString().startsWith(" at index " + i + " "));
|
||||
assertEquals(testString.charAt(i), t2.next());
|
||||
}
|
||||
assertEquals(" at 7 [character 8 line 1]", t2.toString());
|
||||
assertEquals(" at index 7 [character number 8 in line 1]", t2.toString());
|
||||
assertEquals(testString.charAt(7), t2.next());
|
||||
assertEquals(" at 8 [character 0 line 2]", t2.toString());
|
||||
assertEquals(" at index 8 [character number 0 in line 2]", t2.toString());
|
||||
for(int i=8; i<14; i++) {
|
||||
assertTrue(t2.toString().startsWith(" at " + i + " "));
|
||||
assertTrue(t2.toString().startsWith(" at index " + i + " "));
|
||||
assertEquals(testString.charAt(i), t2.next());
|
||||
}
|
||||
assertEquals(" at 14 [character 6 line 2]", t2.toString());
|
||||
assertEquals(" at index 14 [character number 6 in line 2]", t2.toString());
|
||||
assertEquals('\r', t2.next());
|
||||
assertEquals(" at 15 [character 0 line 3]", t2.toString());
|
||||
assertEquals(" at index 15 [character number 0 in line 3]", t2.toString());
|
||||
assertEquals('\n', t2.next());
|
||||
assertEquals(" at 16 [character 0 line 3]", t2.toString());
|
||||
assertEquals(" at index 16 [character number 0 in line 3]", t2.toString());
|
||||
assertEquals('W', t2.next());
|
||||
assertEquals(" at 17 [character 1 line 3]", t2.toString());
|
||||
assertEquals(" at index 17 [character number 1 in line 3]", t2.toString());
|
||||
for(int i=17; i<37; i++) {
|
||||
assertTrue(t2.toString().startsWith(" at " + i + " "));
|
||||
assertTrue(t2.toString().startsWith(" at index " + i + " "));
|
||||
assertEquals(testString.charAt(i), t2.next());
|
||||
}
|
||||
assertEquals(" at 37 [character 1 line 4]", t2.toString());
|
||||
assertEquals(" at index 37 [character number 1 in line 4]", t2.toString());
|
||||
for(int i=37; i<testString.length(); i++) {
|
||||
assertTrue(t2.toString().startsWith(" at " + i + " "));
|
||||
assertTrue(t2.toString().startsWith(" at index " + i + " "));
|
||||
assertEquals(testString.charAt(i), t2.next());
|
||||
}
|
||||
assertEquals(" at "+ testString.length() +" [character 9 line 4]", t2.toString());
|
||||
assertEquals(" at index "+ testString.length() +" [character number 9 in line 4]", t2.toString());
|
||||
// end of the input
|
||||
assertEquals(0, t2.next());
|
||||
assertFalse(t2.more());
|
||||
|
@ -91,7 +91,7 @@ public class XMLConfigurationTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped tag at 176 [character 14 line 4]",
|
||||
"Misshaped tag at index 176 [character number 14 in line 4]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class XMLConfigurationTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 214 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 214 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class XMLConfigurationTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 213 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 213 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ public class XMLConfigurationTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misplaced '<' at 193 [character 4 line 6]",
|
||||
"Misplaced '<' at index 193 [character number 4 in line 6]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class XMLConfigurationTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected 'CDATA[' at 204 [character 11 line 5]",
|
||||
"Expected 'CDATA[' at index 204 [character number 11 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -298,7 +298,7 @@ public class XMLConfigurationTest {
|
||||
" <address>\n"+
|
||||
" <![CDATA[ this is -- <another> comment ]]>\n"+
|
||||
" <name>Joe Tester</name>\n"+
|
||||
" <!-- this is a - multi line \n"+
|
||||
" <!-- this is a - multi in line \n"+
|
||||
" comment -->\n"+
|
||||
" <street>Baker street 5</street>\n"+
|
||||
" </address>\n"+
|
||||
|
@ -93,7 +93,7 @@ public class XMLTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped tag at 176 [character 14 line 4]",
|
||||
"Misshaped tag at index 176 [character number 14 in line 4]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class XMLTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 214 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 214 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class XMLTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misshaped meta tag at 213 [character 12 line 7]",
|
||||
"Misshaped meta tag at index 213 [character number 12 in line 7]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,7 @@ public class XMLTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Misplaced '<' at 193 [character 4 line 6]",
|
||||
"Misplaced '<' at index 193 [character number 4 in line 6]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class XMLTest {
|
||||
fail("Expecting a JSONException");
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Expected 'CDATA[' at 204 [character 11 line 5]",
|
||||
"Expected 'CDATA[' at index 204 [character number 11 in line 5]",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -350,7 +350,7 @@ public class XMLTest {
|
||||
" <address>\n"+
|
||||
" <![CDATA[ this is -- <another> comment ]]>\n"+
|
||||
" <name>Joe Tester</name>\n"+
|
||||
" <!-- this is a - multi line \n"+
|
||||
" <!-- this is a - multi in line \n"+
|
||||
" comment -->\n"+
|
||||
" <street>Baker street 5</street>\n"+
|
||||
" </address>\n"+
|
||||
|
Loading…
x
Reference in New Issue
Block a user