Skip to content

Add jbfl unit tests #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Add jbfl unit tests #6

wants to merge 17 commits into from

Conversation

webdevred
Copy link
Owner

@webdevred webdevred commented Jun 8, 2025

Description

This pull request introduces focused unit tests for the Parsing.DSL module and adds reusable parser test helpers. It also includes minor refactoring and enhancements in core modules to support better testability and correctness.

Changes

New Tests

  • test/Parsing/DSLSpec.hs:

    • Tests parsing of key–property pairs for integer (PadDecimals, PadAmount) and boolean (NoComplexNewLine) types.
    • Includes negative tests verifying expected parse failures with shouldFailWith.
  • test/Parsing/ParsingTestHelpers.hs:

    • Adds applyParserSpec to streamline and simplify parser test definitions.

Note: Before merging, I will add positive and negative tests for node patterns, rules and rulesets.

Refactoring and Enhancements

These changes were necessary to implement the JBFL tests:

  • Formatting.Rules.hs:

    • Adds an Eq instance for SomeProperty.
    • Updates typeclass constraints on PropertyKey to support equality comparisons in tests.
    • Adjusts lookupProp to require Eq for consistency.
  • Parsing.DSL.hs:

    • Refactors parser names for clarity (keyParserobjectKeyParser).
    • Adds objectIndexParser.
    • Exports keyPropertyPairParser for test usage.
  • tools/dump_ast:

    • Added AST generator for generating expected output after parsing Jbfl and Jbeam. This tool is used to create fixture files for automated tests and will support additional tests being added in this PR.

@webdevred webdevred force-pushed the add_jbfl_unit_tests branch 7 times, most recently from 5219c14 to 3d87809 Compare June 15, 2025 22:18
Initially, custom Show instances were designed to mirror the parser
syntax (e.g., `.key`, `[3]`), which seemed intuitive and aligned
with how patterns are written and parsed.

However, this syntax turned out to be ambiguous during debugging.
For example, `.5` could be interpreted as either ObjectKey "5" or
ObjectIndex 5, making it harder to distinguish cases in tests.

Switched to `deriving stock Show` for NodeSelector, NodePath,
NodePatternSelector, and NodePattern to ensure clear, constructor-based
output. Also removed a import (Data.Text) that became unused in NodePath.hs.

This change prioritizes clarity and debuggability over parser-style
aesthetics in internal representations.
Needed for parsing the AST files with expected out AST after parsing the jbfl
and jbeam example files.
@webdevred webdevred force-pushed the add_jbfl_unit_tests branch 5 times, most recently from 597ca41 to e93266b Compare June 18, 2025 16:14
- Introduced `dump-ast` executable to parse and pretty-print ASTs for JBFL and JBEAM files
- Added manual `dump-ast` flag to control whether the executable is built
- Configured cabal and package.yaml to build the executable only when the flag is enabled
- Updated hie.yaml to support IDE tooling for the new executable
- This executable is needed to generate AST files used in the tests being added in this branch
- Allows generating Haskell AST representations from example input files without affecting main builds
- Consolidated AST dumping logic into `saveDump` function in dump_ast tool.
- Updated .gitignore to exclude `cabal.project.local` and backup files.
- Simplified `hie.yaml` by replacing multiple cradle paths with unified cabal components.
- Minor formatting and clarity improvements in `stack.yaml`.
@webdevred webdevred force-pushed the add_jbfl_unit_tests branch from e93266b to e1eeb0d Compare June 18, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant