Skip to content

[core] Implement <esi:choose>, <esi:when>, <esi:otherwise> (#162)#269

Merged
s2x merged 2 commits into
mainfrom
feat/esi-choose-when-otherwise
May 18, 2026
Merged

[core] Implement <esi:choose>, <esi:when>, <esi:otherwise> (#162)#269
s2x merged 2 commits into
mainfrom
feat/esi-choose-when-otherwise

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented May 18, 2026

Summary

Implements conditional content selection via <esi:choose>, <esi:when>, and <esi:otherwise> elements in the core ESI parser.

Closes #162

Changes

  • mesi/parser.go: Added evaluateTest(), extractChooseBlocks(), processChooseBlock(), and depth-aware helper functions for parsing nested choose/when/otherwise blocks
  • mesi/parser_test.go: 20+ unit tests covering all acceptance criteria
  • docs/features.md: Updated feature matrix (⚠️ → ✅) and notes
  • tests/fixtures/: Added e2e fixture (13-esi-choose)

Implementation details

  • Boolean literal test expressions (true/false/0/1)
  • $(...) variable resolution in test attributes
  • Depth-aware block extraction (handles nested <esi:choose>)
  • Supports nesting inside <esi:try> (both attempt and except blocks)
  • Short-circuit evaluation (first matching when wins)
  • Graceful degradation for malformed input

Test coverage

  • test="true" → renders when body
  • test="false" → renders otherwise
  • All false, no otherwise → empty output
  • First match wins (short-circuit)
  • Nested include inside when is processed
  • Empty test → false
  • Malformed (missing close tags) → no panic
  • $(VAR) resolution in test
  • Multiple choose blocks in document
  • Nested choose blocks
  • Choose inside try/attempt and try/except

s2x added 2 commits May 18, 2026 20:19
Implement conditional content selection for ESI:
- <esi:choose> with <esi:when test="..."> branches
- <esi:otherwise> fallback
- Boolean literal evaluation (true/false/0/1)
-  variable resolution in test expressions
- Nested choose, try, include, and vars inside branches
- Depth-aware block extraction with proper nesting support

Adds 20+ unit tests covering all acceptance criteria and an
e2e fixture. Updates feature matrix.
@s2x s2x merged commit 7201008 into main May 18, 2026
4 checks passed
@s2x s2x deleted the feat/esi-choose-when-otherwise branch May 18, 2026 18:27
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.

[core] Implement <esi:choose>, <esi:when>, <esi:otherwise>

1 participant