Skip to content

Commit

Permalink
Deserialize empty tuple as unit (#15)
Browse files Browse the repository at this point in the history
Since Quint v0.19, the unit type is encoded as an empty tuple.
  • Loading branch information
romac authored Mar 26, 2024
2 parents a141ced + eb0df35 commit f849c4e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
1 change: 1 addition & 0 deletions src/de/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
30 changes: 30 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Test>(obj).unwrap();
assert_eq!(itf_value.last_emitted, VKOutput::NoOutput);
}

0 comments on commit f849c4e

Please sign in to comment.