Skip to content

Commit

Permalink
Test more
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Jun 9, 2024
1 parent 944613f commit b6d6dad
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/yaml2candid/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,20 @@ fn can_convert() {
val: IDLValue::None,
}]),
},
TestVec {
description: "Record containing None in conventional form (omission)",
typ: IDLType::RecordT(vec![TypeField {
label: Label::Named("Foo".to_string()),
typ: IDLType::OptT(Box::new(IDLType::PrimT(
candid_parser::types::PrimType::Int8,
))),
}]),
data: YamlValue::Mapping([].into_iter().collect()),
expected_result: IDLValue::Record(vec![IDLField {
id: Label::Named("Foo".to_string()),
val: IDLValue::None,
}]),
},
TestVec {
description: "Record containing Some(5) in canonical form",
typ: IDLType::RecordT(vec![TypeField {
Expand All @@ -500,6 +514,45 @@ fn can_convert() {
val: IDLValue::Opt(Box::new(IDLValue::Int8(8))),
}]),
},
TestVec {
description: "Record containing Some(5) in conventional form",
typ: IDLType::RecordT(vec![TypeField {
label: Label::Named("Foo".to_string()),
typ: IDLType::OptT(Box::new(IDLType::PrimT(
candid_parser::types::PrimType::Int8,
))),
}]),
data: YamlValue::Mapping(
[(YamlValue::from("Foo"), YamlValue::from(8))]
.into_iter()
.collect(),
),
expected_result: IDLValue::Record(vec![IDLField {
id: Label::Named("Foo".to_string()),
val: IDLValue::Opt(Box::new(IDLValue::Int8(8))),
}]),
},
TestVec {
description: "Record containing Some([5]) in conventional form",
typ: IDLType::RecordT(vec![TypeField {
label: Label::Named("Foo".to_string()),
typ: IDLType::OptT(Box::new(IDLType::VecT(Box::new(IDLType::PrimT(
candid_parser::types::PrimType::Int8,
))))),
}]),
data: YamlValue::Mapping(
[(
YamlValue::from("Foo"),
YamlValue::Sequence(vec![YamlValue::from(8)]),
)]
.into_iter()
.collect(),
),
expected_result: IDLValue::Record(vec![IDLField {
id: Label::Named("Foo".to_string()),
val: IDLValue::Opt(Box::new(IDLValue::Vec(vec![IDLValue::Int8(8)]))),
}]),
},
];

for TestVec {
Expand Down

0 comments on commit b6d6dad

Please sign in to comment.