diff --git a/emscripten/test_libqasm.ts b/emscripten/test_libqasm.ts index 2a19b40d..e294e378 100644 --- a/emscripten/test_libqasm.ts +++ b/emscripten/test_libqasm.ts @@ -32,7 +32,7 @@ wrapper().then(function(result: any) { try { let program_2 = "version 3;qubit[5] q;bit[5] b;H q[0:4];b = measure q" let output = cqasm.parse_string_to_json(program_2, "") - let expected_output = String.raw`{"Program":{"version":{"Version":{"items":"3","source_location":":1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":":1:11..19"}},"annotations":[],"source_location":":1:20..21"}},{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":":1:22..28"}},"annotations":[],"source_location":":1:29..30"}},{"GateInstruction":{"gate":{"Gate":{"name":{"Identifier":{"name":"H"}},"gate":"-","parameter":"-","annotations":[],"source_location":":1:31..32"}},"operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexRange":{"first":{"IntegerLiteral":{"value":"0","source_location":":1:35..36"}},"last":{"IntegerLiteral":{"value":"4","source_location":":1:37..38"}}}}]}},"source_location":":1:33..34"}}]}},"annotations":[],"source_location":":1:31..32"}},{"NonGateInstruction":{"name":{"Keyword":{"name":"measure"}},"operands":{"ExpressionList":{"items":[{"Identifier":{"name":"b","source_location":":1:40..41"}},{"Identifier":{"name":"q","source_location":":1:52..53"}}]}},"annotations":[],"source_location":":1:44..51"}}]}}}}` + let expected_output = String.raw`{"Program":{"version":{"Version":{"items":"3","source_location":":1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":":1:11..19"}},"annotations":[],"source_location":":1:20..21"}},{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":":1:22..28"}},"annotations":[],"source_location":":1:29..30"}},{"GateInstruction":{"gate":{"Gate":{"name":{"Identifier":{"name":"H"}},"gate":"-","parameter":"-","annotations":[],"source_location":":1:31..32"}},"operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexRange":{"first":{"IntegerLiteral":{"value":"0","source_location":":1:35..36"}},"last":{"IntegerLiteral":{"value":"4","source_location":":1:37..38"}}}}]}},"source_location":":1:33..34"}}]}},"annotations":[],"source_location":":1:31..32"}},{"NonGateInstruction":{"name":{"Keyword":{"name":"measure"}},"operands":{"ExpressionList":{"items":[{"Identifier":{"name":"b","source_location":":1:40..41"}},{"Identifier":{"name":"q","source_location":":1:52..53"}}]}},"parameter":"-","annotations":[],"source_location":":1:44..51"}}]}}}}` console.log("\nExample 2:", program_2, "\n\tCalling parse_string_to_json...", "\n\tOutput:", output) if (output !== expected_output) { console.log("\tExpected output:", expected_output) @@ -56,7 +56,7 @@ wrapper().then(function(result: any) { try { let program_4 = "version 3;qubit[5] q;bit[5] b;H q[0:4];b = measure q" let output = cqasm.analyze_string_to_json(program_4, "spin_q.cq") - let expected_output = String.raw`{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":[{"GateInstruction":{"instruction_ref":"H(qubit array)","gate":{"Gate":{"name":"H","gate":"-","parameter":"-","annotations":[]}},"operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}},{"ConstInt":{"value":"2"}},{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"4"}}]}}],"annotations":[]}},{"NonGateInstruction":{"instruction_ref":"measure(bit array, qubit array)","name":"measure","operands":[{"VariableRef":{"variable":{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}}},{"VariableRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}}}}],"annotations":[]}}]}},"variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}]}}` + let expected_output = String.raw`{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":[{"GateInstruction":{"instruction_ref":"H(qubit array)","gate":{"Gate":{"name":"H","gate":"-","parameter":"-","annotations":[]}},"operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}},{"ConstInt":{"value":"2"}},{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"4"}}]}}],"annotations":[]}},{"NonGateInstruction":{"instruction_ref":"measure(bit array, qubit array)","name":"measure","operands":[{"VariableRef":{"variable":{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}}},{"VariableRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}}}}],"parameter":"-","annotations":[]}}]}},"variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}]}}` console.log("\nExample 4:", program_4, "\n\tCalling analyze_string_to_json...", "\n\tOutput:", output) if (output !== expected_output) { console.log("\tExpected output:", expected_output)