1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

tests for url fragment notation handling, moving test document to separate file

This commit is contained in:
Bence Erős 2016-04-26 23:01:18 +02:00
parent 9c47ba299d
commit 6211384f87
3 changed files with 62 additions and 11 deletions

3
.gitignore vendored
View file

@ -3,3 +3,6 @@ build
.classpath
.project
.settings/
.gitignore
.gradle
src/main

View file

@ -5,21 +5,30 @@ import static org.junit.Assert.assertSame;
import org.json.JSONObject;
import org.json.JSONPointer;
import org.json.JSONPointerException;
import org.json.JSONTokener;
import org.junit.Test;
public class JSONPointerTest {
private static final JSONObject document = new JSONObject("{"
+ "\"foo\": [\"bar\", \"baz\"], "
+ "\"\": 0,"
+ "\"a/b\": 1,"
+ "\"c%d\": 2,"
+ "\"e^f\": 3,"
+ "\"g|h\": 4," + "\"i\\\\j\": 5,"
+ "\"k\\\"l\": 6,"
+ "\" \": 7,"
+ "\"m~n\": 8"
+ "}");
private static final JSONObject document;
// = new JSONObject("{"
// + "\"foo\": [\"bar\", \"baz\"], "
// + "\"\": 0,"
// + "\"a/b\": 1,"
// + "\"c%d\": 2,"
// + "\"e^f\": 3,"
// + "\"g|h\": 4,"
// + "\"i\\\\j\": 5,"
// + "\"k\\\\\\\"l\": 6,"
// + "\" \": 7,"
// + "\"m~n\": 8"
// + "}");
static {
document = new JSONObject(new JSONTokener(
JSONPointerTest.class.getResourceAsStream("/org/json/junit/jsonpointer-testdoc.json")));
}
private Object query(String pointer) {
return new JSONPointer(pointer).queryFrom(document);
@ -65,11 +74,34 @@ public class JSONPointerTest {
assertSame(document.get("m~n"), query("/m~0n"));
}
@Test
public void backslashEscaping() {
assertSame(document.get("i\\j"), query("/i\\\\j"));
}
@Test
public void quotationEscaping() {
assertSame(document.get("k\"l"), query("/k\\\\\\\"l"));
}
@Test
public void whitespaceKey() {
assertSame(document.get(" "), query("/ "));
}
@Test
public void uriFragmentNotation() {
assertSame(document.get("foo"), query("#/foo"));
}
@Test
public void uriFragmentPercentHandling() {
assertSame(document.get("c%d"), query("#/c%25d"));
assertSame(document.get("e^f"), query("#/e%5Ef"));
assertSame(document.get("g|h"), query("#/g%7Ch"));
assertSame(document.get("m~n"), query("#/m~0n"));
}
@Test(expected = IllegalArgumentException.class)
public void syntaxError() {
new JSONPointer("key");

View file

@ -0,0 +1,16 @@
{
"foo":
[
"bar",
"baz"
],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
}