microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2b583dda267f5bb3df16fbf6251d9bbb86b42b49

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

library/tests/src/lib.rs

36lines · 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)]
7mod test_arrays;
8#[cfg(test)]
9mod test_convert;
10#[cfg(test)]
11mod test_measurement;
12#[cfg(test)]
13mod tests;
14
15use qsc::{
16 interpret::{stateless, GenericReceiver, Value},
17 SourceMap,
18};
19
20/// # Panics
21///
22/// Will panic if compilation fails or the result is not the same as expected.
23pub fn test_expression(expr: &str, expected: &Value) {
24 let mut stdout = vec![];
25 let mut out = GenericReceiver::new(&mut stdout);
26
27 let sources = SourceMap::new([("test".into(), "".into())], Some(expr.into()));
28
29 let interpreter = stateless::Interpreter::new(true, sources).expect("test should compile");
30 let mut eval_ctx = interpreter.new_eval_context();
31 let result = eval_ctx
32 .eval_entry(&mut out)
33 .expect("test should run successfully");
34
35 assert_eq!(expected, &result);
36}
37