diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b40c0a6e..aba3397a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ env: CARGO_INCREMENTAL: 0 RUSTFLAGS: "--cfg=ci_run" MIRIFLAGS: '-Zmiri-permissive-provenance' # Required due to warnings in bitvec 1.0.1 + CI: true # insta snapshots behave differently on ci jobs: check: diff --git a/Cargo.toml b/Cargo.toml index 1a6df4fd6..53a0f81f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,13 @@ webbrowser = "0.8.10" urlencoding = "2.1.2" cool_asserts = "2.0.3" paste = "1.0" +insta = { version = "1.34.0", features = ["yaml"] } [[bench]] name = "bench_main" harness = false + + +[profile.dev.package] +insta.opt-level = 3 +similar.opt-level = 3 \ No newline at end of file diff --git a/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap b/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap new file mode 100644 index 000000000..6a166f9a3 --- /dev/null +++ b/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap @@ -0,0 +1,6 @@ +--- +source: src/hugr/views/tests.rs +expression: h.dot_string() +--- +"digraph {\n0 [shape=plain label=<
(0) DFG
>]\n1 [shape=plain label=<
(1) Input
0: qubit([])1: qubit([])
>]\n1:out0 -> 3:in0 [style=\"\"]\n1:out1 -> 3:in1 [style=\"\"]\n2 [shape=plain label=<
0: qubit([])1: qubit([])
(2) Output
>]\n3 [shape=plain label=<
0: qubit([])1: qubit([])
(3) test.quantum.CX
0: qubit([])1: qubit([])
>]\n3:out0 -> 4:in1 [style=\"\"]\n3:out1 -> 4:in0 [style=\"\"]\n3:out2 -> 4:in2 [style=\"dotted\"]\n4 [shape=plain label=<
0: qubit([])1: qubit([])
(4) test.quantum.CX
0: qubit([])1: qubit([])
>]\n4:out0 -> 2:in0 [style=\"\"]\n4:out1 -> 2:in1 [style=\"\"]\nhier0 [shape=plain label=\"0\"]\nhier0 -> hier1 [style = \"dashed\"] \nhier0 -> hier2 [style = \"dashed\"] \nhier0 -> hier3 [style = \"dashed\"] \nhier0 -> hier4 [style = \"dashed\"] \nhier1 [shape=plain label=\"1\"]\nhier2 [shape=plain label=\"2\"]\nhier3 [shape=plain label=\"3\"]\nhier4 [shape=plain label=\"4\"]\n}\n" + diff --git a/src/hugr/views/tests.rs b/src/hugr/views/tests.rs index 01935e49d..e70a29a3e 100644 --- a/src/hugr/views/tests.rs +++ b/src/hugr/views/tests.rs @@ -1,30 +1,43 @@ use portgraph::PortOffset; +use rstest::{fixture, rstest}; use crate::{ - builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr}, + builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr}, extension::prelude::QB_T, - ops::handle::NodeHandle, + ops::handle::{DataflowOpID, NodeHandle}, type_row, types::FunctionType, utils::test_quantum_extension::cx_gate, - HugrView, + Hugr, HugrView, }; -#[test] -fn node_connections() -> Result<(), BuildError> { +#[fixture] +fn sample_hugr() -> (Hugr, BuildHandle, BuildHandle) { let mut dfg = DFGBuilder::new(FunctionType::new( type_row![QB_T, QB_T], type_row![QB_T, QB_T], - ))?; + )) + .unwrap(); let [q1, q2] = dfg.input_wires_arr(); - let n1 = dfg.add_dataflow_op(cx_gate(), [q1, q2])?; + let n1 = dfg.add_dataflow_op(cx_gate(), [q1, q2]).unwrap(); let [q1, q2] = n1.outputs_arr(); - let n2 = dfg.add_dataflow_op(cx_gate(), [q2, q1])?; + let n2 = dfg.add_dataflow_op(cx_gate(), [q2, q1]).unwrap(); + dfg.add_other_wire(n1.node(), n2.node()).unwrap(); - let h = dfg.finish_prelude_hugr_with_outputs(n2.outputs())?; + ( + dfg.finish_prelude_hugr_with_outputs(n2.outputs()).unwrap(), + n1, + n2, + ) +} +#[rstest] +fn node_connections( + sample_hugr: (Hugr, BuildHandle, BuildHandle), +) -> Result<(), BuildError> { + let (h, n1, n2) = sample_hugr; let connections: Vec<_> = h.node_connections(n1.node(), n2.node()).collect(); assert_eq!( @@ -38,7 +51,19 @@ fn node_connections() -> Result<(), BuildError> { PortOffset::new_outgoing(1).into(), PortOffset::new_incoming(0).into() ], + // order edge + [ + PortOffset::new_outgoing(2).into(), + PortOffset::new_incoming(2).into() + ], ] ); Ok(()) } + +#[rstest] +fn dot_string(sample_hugr: (Hugr, BuildHandle, BuildHandle)) { + let (h, _, _) = sample_hugr; + + insta::assert_yaml_snapshot!(h.dot_string()); +}