Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fd247aca1f |
@@ -196,19 +196,7 @@ impl ObjectStore {
|
||||
}
|
||||
|
||||
fn key_equal(&self, left: &Value, right: &Value) -> Result<bool, VmError> {
|
||||
let text = |value: &Value| -> Result<Option<String>, VmError> {
|
||||
Ok(match value {
|
||||
Value::Text(text) => Some(text.clone()),
|
||||
Value::Object(reference) => self
|
||||
.object(*reference)?
|
||||
.payload()
|
||||
.as_any()
|
||||
.downcast_ref::<EndorStringObject>()
|
||||
.map(|string| string.as_str().to_owned()),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
if let (Some(left), Some(right)) = (text(left)?, text(right)?) {
|
||||
if let (Some(left), Some(right)) = (self.key_text(left)?, self.key_text(right)?) {
|
||||
return Ok(left == right);
|
||||
}
|
||||
match (left, right) {
|
||||
@@ -219,6 +207,19 @@ impl ObjectStore {
|
||||
}
|
||||
}
|
||||
|
||||
fn key_text<'a>(&'a self, value: &'a Value) -> Result<Option<&'a str>, VmError> {
|
||||
Ok(match value {
|
||||
Value::Text(text) => Some(text.as_str()),
|
||||
Value::Object(reference) => self
|
||||
.object(*reference)?
|
||||
.payload()
|
||||
.as_any()
|
||||
.downcast_ref::<EndorStringObject>()
|
||||
.map(EndorStringObject::as_str),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_cell(&mut self, value: Option<Value>) -> Result<ObjectRef, VmError> {
|
||||
self.allocate(EndorCellObject::new(value))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,38 @@ use objects::{
|
||||
Value, VmError,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn dictionary_text_and_managed_string_keys_share_entries_and_keep_first_identity() {
|
||||
let mut store = ObjectStore::new().unwrap();
|
||||
let dict = store.new_dict().unwrap();
|
||||
for text in ["", "camera", "中文🙂"] {
|
||||
let key = store.new_string(text).unwrap();
|
||||
store
|
||||
.dict_set(dict, Value::Object(key), Value::Bool(false))
|
||||
.unwrap();
|
||||
store
|
||||
.dict_set(dict, Value::Text(text.into()), Value::Bool(true))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
store.dict_get_name(dict, text).unwrap(),
|
||||
Some(Value::Bool(true))
|
||||
);
|
||||
assert_eq!(
|
||||
store.dict_items(dict).unwrap().last().unwrap().0,
|
||||
Value::Object(key)
|
||||
);
|
||||
assert_eq!(
|
||||
store.dict_get(dict, &Value::Object(key)).unwrap(),
|
||||
Some(Value::Bool(true))
|
||||
);
|
||||
store.release(key).unwrap();
|
||||
assert!(store.dict_delete(dict, &Value::Text(text.into())).unwrap());
|
||||
assert_eq!(store.dict_get_name(dict, text).unwrap(), None);
|
||||
}
|
||||
store.release(dict).unwrap();
|
||||
assert_eq!(store.object_count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standalone_storage_preserves_identity_validates_edges_and_collects_cycles() {
|
||||
let mut store = ObjectStore::new().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user