MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / is

Function is

crates/core/tests/tests.rs:172–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170
171#[test]
172fn is() {
173 // `is<T>` is true for `Error::msg(T)`
174 let e = Error::msg("str");
175 assert!(e.is::<&str>());
176 assert!(!e.is::<TestError>());
177 assert!(!e.is::<OutOfMemory>());
178
179 // `is<T>` is true for `T` in the context chain.
180 let e = e.context(TestError(42));
181 assert!(e.is::<&str>());
182 assert!(e.is::<TestError>());
183 assert!(!e.is::<OutOfMemory>());
184
185 // `is<T>` is still true when there are multiple `T`s and `U`s in the
186 // chain.
187 let e = e.context(TestError(36)).context("another str");
188 assert!(e.is::<&str>());
189 assert!(e.is::<TestError>());
190 assert!(!e.is::<OutOfMemory>());
191
192 // `is<T>` is true for `Error::from(T)`.
193 let e = Error::from(TestError(36));
194 assert!(e.is::<TestError>());
195 assert!(!e.is::<&str>());
196 assert!(!e.is::<OutOfMemory>());
197
198 // `is<T>` is true for `Error::from(OutOfMemory)`.
199 let e = Error::from(OutOfMemory::new(5));
200 assert!(e.is::<OutOfMemory>());
201 assert!(!e.is::<TestError>());
202 assert!(!e.is::<&str>());
203}
204
205#[test]
206fn is_for_root_cause_with_initial_error_source() {

Callers 1

is_typedMethod · 0.50

Calls 5

msgFunction · 0.85
fromFunction · 0.85
TestErrorClass · 0.70
newFunction · 0.70
contextMethod · 0.45

Tested by

no test coverage detected