chore: initial unit tests

This commit is contained in:
katldewitt 2021-10-24 08:41:57 -07:00
parent 93f4b34890
commit 30a70c8886

View File

@ -135,6 +135,14 @@ public class JSONPointerTest {
assertEquals(6, query("/k\"l"));
}
/**
* KD Added
* */
@Test
public void quotationEscaping() {
assertEquals(document.get("k\"l"), query("/k\\\"l"));
}
@Test
public void whitespaceKey() {
assertEquals(7, query("/ "));
@ -389,4 +397,33 @@ public class JSONPointerTest {
obj = jsonArray.optQuery(new JSONPointer("/a/b/c"));
assertTrue("Expected null", obj == null);
}
/**
* KD added
* Coverage for JSONObject query(JSONPointer)
*/
@Test
public void queryFromJSONObjectUsingPointer2() {
String str = "{"+
"\"string\\\\\\\\Key\":\"hello world!\","+
"}"+
"}";
JSONObject jsonObject = new JSONObject(str);
Object obj = jsonObject.optQuery(new JSONPointer("/string\\\\\\\\Key"));
assertTrue("Expected 'hello world!'", "hello world!".equals(obj));
}
/**
* KD added - understanding behavior
* Coverage for JSONObject query(JSONPointer)
*/
@Test
public void queryFromJSONObjectUsingPointer0() {
String str = "{"+
"\"string\\\\Key\":\"hello world!\","+
"}"+
"}";
JSONObject jsonObject = new JSONObject(str);
Object obj = jsonObject.optQuery(new JSONPointer("/string\\Key"));
assertTrue("Expected 'hello world!'", "hello world!".equals(obj));
}
}