Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

✅ Add unit-level tests for `parseClassicConditionExpression`

未关闭
#469 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
84/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
testing-qa

调研方向

从 src/common/parsing/CodePreprocessing.cpp 中的 parseClassicConditionExpression 开始,并检查 test/test_custom_code.cpp 中现有的覆盖范围。在 test_parsing.cpp 或新的测试文件中添加一个 fixture,检查针对所列有效、无效和 permissive 情况返回的 std::optional。完成标准是直接针对所有指定输入测试 parser,包括可能因 issue #468 而改变的行为。

由索引模型根据 Issue 内容生成。

描述

🤖 AI text below 🤖

Problem statement

parseClassicConditionExpression (in src/common/parsing/CodePreprocessing.cpp) has no direct unit tests. Every test that exercises it today lives in test/test_custom_code.cpp and runs the full end-to-end pipeline: load QASM code, spin up a DDSimulationState, run the simulation, and inspect amplitudes or classical bits.

Two problems with that coverage:

  • A parser bug shows up as a failed amplitude assertion, not as "the parser returned the wrong ClassicCondition". Localizing the root cause takes longer than it should.
  • Edge cases of the parser itself (malformed input, whitespace, leading paren, trailing garbage, invalid brackets, empty operand) are not systematically covered because writing a full QASM program to trigger each one is disproportionate.

Surfaced during the review of PR #463 while considering the follow-ups for parseClassicConditionExpression.

Proposed solution

Add a fixture (either in the existing test_parsing.cpp or in a new file) that calls parseClassicConditionExpression directly with a string and checks the returned std::optional<ClassicCondition> against expected values. Cover:

  • Valid cases: one test per comparator (==, !=, <, <=, >, >=), bracketed forms (c[0] == 1), bare register (c), bare bit (c[0]), input with leading (, input with surrounding whitespace.
  • Invalid cases: empty string, missing operand on either side, non-numeric right-hand side, malformed brackets (open only, close only, index empty, non-digit index, bracket not at the end), out-of-range integer literal.
  • Document currently permissive behavior (e.g. c2] accepted as a register name, @# accepted). These tests can start green against the current behavior and flip to expect std::nullopt once #468 lands.
Out of scope
  • Unit tests for other parsers in the file (parseFunctionDefinition, parseClassicControlledGate, etc.). Same idea, separate issue.
  • Testing parseBitRegisterRef directly. It lives in the anonymous namespace of the .cpp; the tests here cover it indirectly through parseClassicConditionExpression, which is what the outside world sees.
主要语言
C++
星标
21
派生
8
平均合并
5 小时 17 分钟
30 天内合并 PR
21

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

munich-quantum-toolkit/debugger 的其他 Issue

查看 munich-quantum-toolkit/debugger 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。