Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize empty tuple as unit #15

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading