diff --git a/CHANGELOG.md b/CHANGELOG.md index 3414165..e37bce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Unreleased + +- Compatibility with Quint v0.19.0 +- Deserialize empty tuple as unit ([#15](https://github.com/informalsystems/itf-rs/pull/15)) + ## v0.2.2 *December 7th, 2023* diff --git a/src/de/deserializer.rs b/src/de/deserializer.rs index 4f88231..0dfea1e 100644 --- a/src/de/deserializer.rs +++ b/src/de/deserializer.rs @@ -73,6 +73,7 @@ impl<'de> Deserializer<'de> for Value { Value::String(v) => visitor.visit_string(v), Value::BigInt(v) => visit_bigint(v, visitor), Value::List(v) => visit_list(v, visitor), + Value::Tuple(v) if v.is_empty() => visitor.visit_unit(), Value::Tuple(v) => visit_tuple(v, visitor), Value::Set(v) => visit_set(v, visitor), Value::Record(v) => visit_record(v, visitor), diff --git a/tests/regression.rs b/tests/regression.rs index c580923..37f7133 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -215,6 +215,7 @@ fn test_failed_bare_bigint_to_int() { fn test_complete() { use std::collections::{BTreeSet, HashMap, HashSet}; + #[allow(dead_code)] #[derive(Deserialize, Debug)] #[serde(untagged)] enum RecordEnum { @@ -251,3 +252,32 @@ fn test_complete() { let _: Complete = itf::from_value(itf).unwrap(); } + +// Test extracted from the malachite MBT tests +#[test] +fn test_enum_unit_variant() { + #[derive(Debug, PartialEq, Deserialize)] + #[serde(tag = "tag", content = "value")] + pub enum VKOutput { + #[serde(rename = "NoVKOutput")] + NoOutput, + } + + let obj = serde_json::json!({ + "lastEmitted": { + "tag": "NoVKOutput", + "value": { + "#tup": [] + } + } + }); + + #[derive(serde::Deserialize)] + #[serde(rename_all = "camelCase")] + struct Test { + last_emitted: VKOutput, + } + + let itf_value = itf::from_value::(obj).unwrap(); + assert_eq!(itf_value.last_emitted, VKOutput::NoOutput); +}