1#![warn(missing_docs)]
20
21mod labeled_formatter;
22
23pub use labeled_formatter::{
24 FormattedValue, QShotValType, QirLabeledFormatter, QirMetadata, QirOutput, QsysShot,
25 QsysShotItem, QsysShotItemValue, QsysShots,
26};
27
28#[cfg(feature = "python")]
29mod python;
30
31#[cfg(feature = "python")]
32#[pyo3::pymodule]
33mod _native {
34 #[pymodule_export]
35 use crate::python::PythonQirLabeledFormatter;
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
43
44 #[test]
46 fn test_top_level_exports_support_basic_usage() {
47 let value: QShotValType = QShotValType::Int(42);
48 let item: QsysShotItem = ("USER:INT:answer".into(), QsysShotItemValue::Scalar(value));
49 let shot: QsysShot = vec![item];
50 let results: QsysShots = vec![shot];
51
52 let output = QirLabeledFormatter::new().qir_labeled_output(&results, &QirMetadata::new());
53
54 assert!(output.contains("OUTPUT\tINT\t42\tanswer\n"));
55 }
56
57 #[test]
59 fn test_top_level_formatter_can_emit_values() {
60 let mut output = QirOutput::default();
61 QirLabeledFormatter::new().emit(
62 &mut output,
63 "RESULT_ARRAY",
64 Some("bits"),
65 &QsysShotItemValue::List(vec![
66 QShotValType::Int(1),
67 QShotValType::Int(0),
68 QShotValType::Int(1),
69 ]),
70 );
71
72 assert_eq!(output.text, "OUTPUT\tRESULT_ARRAY\t101\tbits\n");
73 }
74
75 #[test]
77 fn test_python_version_is_dynamic() {
78 let pyproject = include_str!("../pyproject.toml");
79 let project = pyproject
80 .split_once("[project]")
81 .expect("pyproject.toml must contain a [project] table")
82 .1
83 .split("\n[")
84 .next()
85 .unwrap();
86
87 assert!(
88 project
89 .lines()
90 .any(|line| line.trim() == r#"dynamic = ["version"]"#)
91 );
92 assert!(
93 !project
94 .lines()
95 .any(|line| line.trim().starts_with("version ="))
96 );
97 }
98}