Skip to content

Refactor test helpers in test-reader-parser.cpp and test-buffer-parser.cpp to use common/shared utilities #188

@coderabbitai

Description

@coderabbitai

Description

Both test-reader-parser.cpp and test-buffer-parser.cpp contain nearly identical test helper functions and data structures that should be refactored into a common/shared test utility module.

Duplicated Code

Shared Data Structures

Both files define:

  • CapturePositions struct
  • ExpectedToken struct
  • ExpectedEvent struct

Shared Helper Functions

Both files implement:

  • parse_and_validate() - validates parsed events against expected tokens and captures (with parser-specific differences)
  • serialize_id_symbol_map() - serializes the id-to-symbol map (identical implementation)

Proposed Refactoring

  1. Create a common test utilities header/source file (e.g., tests/common/test-parser-helpers.hpp).
  2. Move the shared data structures to the common utility.
  3. Extract the common validation logic from parse_and_validate() into reusable helper functions.
  4. Use templates or function overloading to handle parser-specific differences (BufferParser vs ReaderParser).
  5. Move serialize_id_symbol_map() to the common utility.

Benefits

  • Reduces code duplication
  • Easier maintenance when validation logic needs to be updated
  • Promotes consistency across test files
  • Simplifies adding new parser test files in the future

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions