microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
library/tests/src/lib.rs
29lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | #![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)] |
| 5 | |
| 6 | #[cfg(test)] |
| 7 | mod tests; |
| 8 | |
| 9 | use qsc::{ |
| 10 | interpret::{stateless, GenericReceiver, Value}, |
| 11 | SourceMap, |
| 12 | }; |
| 13 | |
| 14 | /// # Panics |
| 15 | /// |
| 16 | /// Will panic if compilation fails or the result is not the same as expected. |
| 17 | pub fn run_stdlib_test(expr: &str, expected: &Value) { |
| 18 | let mut stdout = vec![]; |
| 19 | let mut out = GenericReceiver::new(&mut stdout); |
| 20 | |
| 21 | let sources = SourceMap::new([("test".into(), "".into())], Some(expr.into())); |
| 22 | |
| 23 | let context = stateless::Context::new(true, sources).expect("test should compile"); |
| 24 | let result = context |
| 25 | .eval(&mut out) |
| 26 | .expect("test should run successfully"); |
| 27 | |
| 28 | assert_eq!(expected, &result); |
| 29 | } |
| 30 | |