Skip to content

Commit

Permalink
Change gen JSON output from stream to array (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinamogit authored Dec 2, 2022
1 parent 1fbeebe commit c87a13a
Showing 1 changed file with 118 additions and 114 deletions.
232 changes: 118 additions & 114 deletions soroban-spec/src/gen/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ pub fn generate_from_wasm(wasm: &[u8]) -> Result<String, FromWasmError> {
}

pub fn generate(spec: &[ScSpecEntry]) -> String {
spec.iter()
.map(Entry::from)
.map(|e| serde_json::to_string_pretty(&e).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived"))
.collect()
let collected: Vec<_> = spec.iter().map(Entry::from).collect();
serde_json::to_string_pretty(&collected).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived")
}

#[cfg(test)]
Expand All @@ -71,126 +69,132 @@ mod test {
let json = generate(&entries);
assert_eq!(
json,
r#"{
"type": "enum",
"name": "UdtEnum2",
"cases": [
{
"name": "A",
"value": 10
},
{
"name": "B",
"value": 15
}
]
}{
"type": "union",
"name": "UdtEnum",
"cases": [
{
"name": "UdtA",
"values": []
},
{
"name": "UdtB",
"values": [
{
"type": "custom",
"name": "UdtStruct"
r#"[
{
"type": "enum",
"name": "UdtEnum2",
"cases": [
{
"name": "A",
"value": 10
},
{
"name": "B",
"value": 15
}
]
},
{
"type": "union",
"name": "UdtEnum",
"cases": [
{
"name": "UdtA",
"values": []
},
{
"name": "UdtB",
"values": [
{
"type": "custom",
"name": "UdtStruct"
}
]
},
{
"name": "UdtC",
"values": [
{
"type": "custom",
"name": "UdtEnum2"
}
]
},
{
"name": "UdtD",
"values": [
{
"type": "custom",
"name": "UdtTuple"
}
]
}
]
},
{
"type": "struct",
"name": "UdtTuple",
"fields": [
{
"name": "0",
"value": {
"type": "i64"
}
]
},
{
"name": "UdtC",
"values": [
{
"type": "custom",
"name": "UdtEnum2"
},
{
"name": "1",
"value": {
"type": "vec",
"element": {
"type": "i64"
}
}
]
},
{
"name": "UdtD",
"values": [
{
"type": "custom",
"name": "UdtTuple"
}
]
}
]
}{
"type": "struct",
"name": "UdtTuple",
"fields": [
{
"name": "0",
"value": {
"type": "i64"
}
},
{
"name": "1",
"value": {
"type": "vec",
"element": {
]
},
{
"type": "struct",
"name": "UdtStruct",
"fields": [
{
"name": "a",
"value": {
"type": "i64"
}
}
}
]
}{
"type": "struct",
"name": "UdtStruct",
"fields": [
{
"name": "a",
"value": {
"type": "i64"
}
},
{
"name": "b",
"value": {
"type": "i64"
}
},
{
"name": "c",
"value": {
"type": "vec",
"element": {
},
{
"name": "b",
"value": {
"type": "i64"
}
},
{
"name": "c",
"value": {
"type": "vec",
"element": {
"type": "i64"
}
}
}
}
]
}{
"type": "function",
"name": "add",
"inputs": [
{
"name": "a",
"value": {
"type": "custom",
"name": "UdtEnum"
]
},
{
"type": "function",
"name": "add",
"inputs": [
{
"name": "a",
"value": {
"type": "custom",
"name": "UdtEnum"
}
},
{
"name": "b",
"value": {
"type": "custom",
"name": "UdtEnum"
}
}
},
{
"name": "b",
"value": {
"type": "custom",
"name": "UdtEnum"
],
"outputs": [
{
"type": "i64"
}
}
],
"outputs": [
{
"type": "i64"
}
]
}"#,
]
}
]"#,
);
}
}

0 comments on commit c87a13a

Please sign in to comment.