Skip to content

Commit 4f36fc3

Browse files
committed
Fix type to_string function
1 parent a2591bb commit 4f36fc3

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/type.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ impl Display for Type {
8686
Type::String => write!(f, "String"),
8787
Type::BNum => write!(f, "BNum"),
8888
Type::Bool => write!(f, "Bool"),
89-
// TODO: Fix map type
90-
Type::Map(ref k, ref v) => write!(f, "MapType ({}, {})", k, v),
91-
Type::Option(ref k) => write!(f, "Option ({})", k),
92-
Type::List(ref k) => write!(f, "List ({})", k),
93-
Type::Pair(ref k, ref v) => write!(f, "Pair ({}, {})", k, v),
89+
Type::Map(ref k, ref v) => write!(f, "(Map {}, {})", k, v),
90+
Type::Option(ref k) => write!(f, "(Option {})", k),
91+
Type::List(ref k) => write!(f, "(List {})", k),
92+
Type::Pair(ref k, ref v) => write!(f, "(Pair {} {})", k, v),
9493
Type::ByStr(n) => write!(f, "ByStr{}", n),
9594
Type::Other(ref s) => write!(f, "{}", s),
9695
}
@@ -155,4 +154,38 @@ mod tests {
155154

156155
assert_eq!(option_bool_type, Type::Option(Box::new(Type::Bool)));
157156
}
157+
158+
#[test]
159+
fn test_type_to_string() {
160+
//(List (Pair ByStr20 (List (Pair ByStr20 Uint32))))
161+
let list_type = Type::List(Box::new(Type::Pair(
162+
Box::new(Type::ByStr(20)),
163+
Box::new(Type::List(Box::new(Type::Pair(
164+
Box::new(Type::ByStr(20)),
165+
Box::new(Type::Uint32),
166+
)))),
167+
)));
168+
169+
assert_eq!(
170+
"(List (Pair ByStr20 (List (Pair ByStr20 Uint32))))",
171+
list_type.to_string()
172+
);
173+
174+
// (List (Pair ByStr20 (List (Pair ByStr20 (List (Pair Uint32 Uint128))))))
175+
let list_type = Type::List(Box::new(Type::Pair(
176+
Box::new(Type::ByStr(20)),
177+
Box::new(Type::List(Box::new(Type::Pair(
178+
Box::new(Type::ByStr(20)),
179+
Box::new(Type::List(Box::new(Type::Pair(
180+
Box::new(Type::Uint32),
181+
Box::new(Type::Uint128),
182+
)))),
183+
)))),
184+
)));
185+
186+
assert_eq!(
187+
"(List (Pair ByStr20 (List (Pair ByStr20 (List (Pair Uint32 Uint128))))))",
188+
list_type.to_string()
189+
);
190+
}
158191
}

0 commit comments

Comments
 (0)