Commit eb147ef0 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Fix dictionary issues with String/FString mismatch

Change-Id: If4549950bac9bd0aa35efdb7f5f77f70242cfe38
parent 6a9dbfd3
......@@ -52,7 +52,7 @@ Blockly.Yail.YAIL_CLOSE_BLOCK = ")\n";
Blockly.Yail.YAIL_COMMENT_MAJOR = ";;; ";
Blockly.Yail.YAIL_COMPONENT_REMOVE = "(remove-component ";
Blockly.Yail.YAIL_COMPONENT_TYPE = "component";
Blockly.Yail.YAIL_CONSTANT_ALL = 'com.google.appinventor.components.runtime.util.YailDictionary:ALL';
Blockly.Yail.YAIL_CONSTANT_ALL = '(static-field com.google.appinventor.components.runtime.util.YailDictionary \'ALL)';
Blockly.Yail.YAIL_DEFINE = "(def ";
Blockly.Yail.YAIL_DEFINE_EVENT = "(define-event ";
Blockly.Yail.YAIL_DEFINE_GENERIC_EVENT = '(define-generic-event ';
......
......@@ -2497,8 +2497,6 @@ Dictionary implementation.
(*:remove (as YailDictionary yail-dictionary) key))
(define (yail-dictionary-lookup key yail-dictionary default)
(android-log
(format #f "Dictionary lookup key is ~A and table is ~A" key yail-dictionary))
(let ((result
(cond ((instance? yail-dictionary YailList)
(yail-alist-lookup key yail-dictionary default))
......@@ -2534,8 +2532,6 @@ Dictionary implementation.
(*:size (as YailDictionary yail-dictionary)))
(define (yail-dictionary-alist-to-dict alist)
(android-log
(format #f "List alist table is ~A" alist))
(let loop ((pairs-to-check (yail-list-contents alist)))
(cond ((null? pairs-to-check) "The list of pairs has a null pair")
((not (pair-ok? (car pairs-to-check)))
......
......@@ -512,6 +512,49 @@ public class YailDictionary extends LinkedHashMap<Object, Object>
}
}
@Override
public boolean containsKey(Object key) {
if (key instanceof FString) {
return super.containsKey(key.toString());
}
return super.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
if (value instanceof FString) {
return super.containsValue(value.toString());
}
return super.containsValue(value);
}
@Override
public Object get(Object key) {
if (key instanceof FString) {
return super.get(key.toString());
}
return super.get(key);
}
@Override
public Object put(Object key, Object value) {
if (key instanceof FString) {
key = key.toString();
}
if (value instanceof FString) {
value = value.toString();
}
return super.put(key, value);
}
@Override
public Object remove(Object key) {
if (key instanceof FString) {
return super.remove(key.toString());
}
return super.remove(key);
}
@Override
public String toString() {
try {
......@@ -539,7 +582,6 @@ public class YailDictionary extends LinkedHashMap<Object, Object>
}
@NonNull
@SuppressWarnings("NullableProblems")
@Override
public Iterator<YailList> iterator() {
return new DictIterator(entrySet().iterator());
......
......@@ -14,6 +14,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.google.appinventor.components.runtime.collect.Lists;
import com.google.appinventor.components.runtime.errors.DispatchableError;
......@@ -159,6 +160,24 @@ public class YailDictionaryTest {
dict.setValueForKeyPath(Arrays.asList((Object) "foo", -1), false);
}
@Test
public void testFString() {
YailDictionary target = new YailDictionary();
target.put("key", "value");
target.put(new FString("fstringkey"), new FString("fstringvalue"));
assertTrue(target.containsKey(new FString("key")));
assertTrue(target.containsValue(new FString("value")));
assertTrue(target.containsKey("fstringkey"));
assertTrue(target.containsValue("fstringvalue"));
assertEquals("value", target.get("key"));
assertEquals("value", target.get(new FString("key")));
assertEquals("fstringvalue", target.get("fstringkey"));
assertEquals("fstringvalue", target.get(new FString("fstringkey")));
target.remove(new FString("key"));
target.remove(new FString("fstringkey"));
assertTrue(target.isEmpty());
}
@Test
public void testToString() {
YailDictionary dict = YailDictionary.makeDictionary();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment