Skip to content

Commit

Permalink
Expand Rust alias to branded to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Nov 21, 2024
1 parent 2ca2719 commit 27126de
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lang/rs/converter/src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ impl RSConvert<RSDefinition> for GTAlias {
RSDefinition::Struct(object.convert(context)?)
}

GTDescriptor::Branded(branded) => {
context.provide_definition_id(self.id.clone());
context.provide_doc(doc);
RSDefinition::Struct(branded.convert(context)?)
}

GTDescriptor::Union(union) => {
context.provide_definition_id(self.id.clone());
context.provide_doc(doc);
Expand Down Expand Up @@ -140,6 +146,37 @@ mod tests {
);
}

#[test]
fn test_convert_branded() {
assert_eq!(
GTAlias {
id: GTDefinitionId("module".into(), "BookId".into()),
span: (0, 0).into(),
doc: None,
attributes: vec![],
name: GTIdentifier::new((0, 0).into(), "BookId".into()),
descriptor: GTDescriptor::Branded(GTBranded::Int(
(0, 0).into(),
GTDefinitionId("module".into(), "BookId".into()),
GTIdentifier((0, 0).into(), "BookId".into())
))
.into(),
}
.convert(&mut RSConvertContext::empty("module".into()))
.unwrap(),
RSDefinition::Struct(RSStruct {
id: GTDefinitionId("module".into(), "BookId".into()),
doc: None,
attributes: vec![
"derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)".into()
],
name: "BookId".into(),
fields: RSStructFields::Tuple(vec![RSDescriptor::Primitive(RSPrimitive::Int),])
.into(),
}),
);
}

#[test]
fn test_convert_hoisted() {
let mut context = RSConvertContext::empty("module".into());
Expand Down

0 comments on commit 27126de

Please sign in to comment.