Skip to content

Commit 77c0eda

Browse files
authored
feat: add integration and rule-based tests for various QASM features (#9)
1 parent 8a3c287 commit 77c0eda

File tree

18 files changed

+106
-3
lines changed

18 files changed

+106
-3
lines changed

src/format.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,24 @@ fn format_barrier(b: ast::Barrier) -> Doc {
334334
}
335335

336336
fn format_assignment(a: ast::AssignmentStmt) -> Doc {
337-
Doc::text(a.syntax().text().to_string().trim())
337+
let mut parts = vec![];
338+
339+
if let Some(idx) = a.indexed_identifier() {
340+
parts.push(format_indexed_identifier(&idx));
341+
} else if let Some(id) = a.identifier() {
342+
parts.push(Doc::text(
343+
id.ident_token().map(|t| t.to_string()).unwrap_or_default(),
344+
));
345+
}
346+
347+
parts.push(Doc::text(" = "));
348+
349+
if let Some(rhs) = a.rhs() {
350+
parts.push(format_expr(rhs));
351+
}
352+
353+
parts.push(Doc::text(";"));
354+
Doc::concat(parts)
338355
}
339356

340357
fn format_classical_decl(c: ast::ClassicalDeclarationStatement) -> Doc {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENQASM 3.0;
2+
qubit q;
3+
bit c;
4+
c=measure q;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENQASM 3.0;
2+
qubit q;
3+
bit c;
4+
c = measure q;

tests/fixtures/barrier/input.qasm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENQASM 3.0;
2+
qubit[2] q;
3+
barrier q[0],q[1];

tests/fixtures/barrier/output.qasm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENQASM 3.0;
2+
qubit[2] q;
3+
barrier q[0], q[1];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENQASM 3.0;
2+
qubit[2]q;
3+
bit[4]c;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENQASM 3.0;
2+
qubit[2] q;
3+
bit[4] c;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENQASM 3.0;
2+
qubit[2] q;
3+
h q[0];
4+
cx q[0],q[1];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENQASM 3.0;
2+
qubit[2] q;
3+
h q[0];
4+
cx q[0], q[1];

0 commit comments

Comments
 (0)