Skip to content

Commit 22750f6

Browse files
committed
Testing the identity of inspector-related objects.
1 parent 6196a16 commit 22750f6

File tree

1 file changed

+42
-0
lines changed
  • tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test

1 file changed

+42
-0
lines changed

tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/InteropTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
*/
2525
package com.oracle.truffle.tools.chromeinspector.test;
2626

27+
import static org.junit.Assert.assertFalse;
2728
import static org.junit.Assert.assertTrue;
2829

2930
import com.oracle.truffle.api.interop.InteropException;
3031
import com.oracle.truffle.api.interop.InteropLibrary;
3132
import com.oracle.truffle.tools.chromeinspector.objects.JSONTruffleArray;
33+
import com.oracle.truffle.tools.chromeinspector.objects.JSONTruffleObject;
3234
import org.graalvm.shadowed.org.json.JSONArray;
35+
import org.graalvm.shadowed.org.json.JSONObject;
3336

3437
import org.junit.Test;
3538

@@ -61,4 +64,43 @@ public void testJSONTruffleArraySort() throws InteropException {
6164
}
6265
}
6366

67+
private static void testIdentity(Object theObject, Object sameObject, Object differentObject) {
68+
InteropLibrary interop = InteropLibrary.getUncached(theObject);
69+
assertTrue(interop.hasIdentity(theObject));
70+
assertTrue(interop.isIdentical(theObject, sameObject, interop));
71+
assertFalse(interop.isIdentical(theObject, differentObject, interop));
72+
}
73+
74+
@Test
75+
public void testJSONTruffleArrayIdentity() {
76+
String json = "[42, 211]";
77+
JSONArray jsonArray = new JSONArray(json);
78+
Object array = new JSONTruffleArray(jsonArray);
79+
Object sameArray = new JSONTruffleArray(jsonArray);
80+
Object anotherArray = new JSONTruffleArray(new JSONArray(json));
81+
testIdentity(array, sameArray, anotherArray);
82+
}
83+
84+
@Test
85+
public void testJSONTruffleObjectIdentity() {
86+
String json = "{ answer: 42, question: '?' }";
87+
JSONObject jsonObject = new JSONObject(json);
88+
JSONTruffleObject object = new JSONTruffleObject(jsonObject);
89+
Object sameObject = new JSONTruffleObject(jsonObject);
90+
Object anotherObject = new JSONTruffleObject(new JSONObject(json));
91+
testIdentity(object, sameObject, anotherObject);
92+
}
93+
94+
@Test
95+
public void testJSONKeysIdentity() throws InteropException {
96+
String json = "{ answer: 42, question: '?' }";
97+
JSONObject jsonObject = new JSONObject(json);
98+
JSONTruffleObject truffleObject = new JSONTruffleObject(jsonObject);
99+
InteropLibrary interop = InteropLibrary.getUncached();
100+
Object keys = interop.getMembers(truffleObject);
101+
Object sameKeys = interop.getMembers(truffleObject);
102+
Object otherKeys = interop.getMembers(new JSONTruffleObject(jsonObject));
103+
testIdentity(keys, sameKeys, otherKeys);
104+
}
105+
64106
}

0 commit comments

Comments
 (0)