Skip to content

jinja whitespace tests#72

Merged
ngxson merged 3 commits intongxson:xsn/jinja_vmfrom
aldehir:jinja-vm-whitespace
Jan 4, 2026
Merged

jinja whitespace tests#72
ngxson merged 3 commits intongxson:xsn/jinja_vmfrom
aldehir:jinja-vm-whitespace

Conversation

@aldehir
Copy link

@aldehir aldehir commented Jan 4, 2026

Moved the testing.h helper out of peg-parser in case it's useful, not really required.

Added whitespace tests, took a few from the Jinja code base and then added one along with the expected string from jinja.h.

Adjusted the spacing rules. The default in Jinja is lstrip_blocks = False and trim_blocks = False. It seems this used to be done in the preprocessing step, but was removed. That's probably fine, I haven't seen a template that adjusts those settings (not sure how they could). These updates should better align to those defaults.

Original:

whitespace
  no whitespace control
  ASSERTION FAILED : Template render mismatch
    Template: "    {% if True %}\n    {% endif %}"
    Expected: "    \n    "
    Actual  : ""
  ASSERTION FAILED : Template render mismatch
    Template: "  {% if kvs %}   {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}  {% endif %}"
    Expected: "     a=1 b=2   "
    Actual  : "a=1b=2"
  no whitespace control (2 of 2 assertion(s) failed)                            [FAIL]
  leading whitespace control
  ASSERTION FAILED : Template render mismatch
    Template: "  {%- if kvs %}   {%- for k, v in kvs %}{{ k }}={{ v }} {% endfor -%}  {%- endif %}"
    Expected: "a=1 b=2 "
    Actual  : "a=1b=2"
  ASSERTION FAILED : Template render mismatch
    Template: "{{- ']~b[ai' ~ '\\n' }}\n\n{%- set reasoning_content = ''%}"
    Expected: "]~b[ai\n"
    Actual  : "]~b[ai\n\n"
  leading whitespace control (2 of 2 assertion(s) failed)                       [FAIL]
whitespace (4 of 4 assertion(s) failed)                                         [FAIL]

tests      : 3
assertions : 4
failures   : 4
exceptions : 0

With this PR:

whitespace
  no whitespace control
  no whitespace control (2 assertion(s))                                        [PASS]
  leading whitespace control
  leading whitespace control (2 assertion(s))                                   [PASS]
whitespace (4 assertion(s))                                                     [PASS]

tests      : 3
assertions : 4
failures   : 0
exceptions : 0

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ngxson ngxson merged commit 14a8706 into ngxson:xsn/jinja_vm Jan 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants