MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / test_variant_roundtrip

Function test_variant_roundtrip

tests/runtime/map/runner.rs:146–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

144}
145
146fn test_variant_roundtrip() {
147 let mut map = NamesById::new();
148 map.insert(1, "one".to_string());
149 let as_map = variant_roundtrip(&MapOrString::AsMap(map));
150 match &as_map {
151 MapOrString::AsMap(m) => {
152 assert_eq!(m.get(&1).map(String::as_str), Some("one"));
153 }
154 MapOrString::AsString(_) => panic!("expected AsMap"),
155 }
156
157 let as_str = variant_roundtrip(&MapOrString::AsString("hello".to_string()));
158 match &as_str {
159 MapOrString::AsString(s) => assert_eq!(s, "hello"),
160 MapOrString::AsMap(_) => panic!("expected AsString"),
161 }
162}
163
164fn test_result_roundtrip() {
165 let mut map = NamesById::new();

Callers 1

runMethod · 0.70

Calls 3

newFunction · 0.85
insertMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected