228 lines
7.8 KiB
Gherkin
228 lines
7.8 KiB
Gherkin
Feature: YAML Template Engine coverage
|
|
Background:
|
|
Given the YAML template engine is initialized for coverage
|
|
|
|
Scenario: Postprocess splits combined mapping values
|
|
Given I have YAML with specific line splitting pattern:
|
|
"""
|
|
config:
|
|
combined: value1 key2: value2
|
|
test: normal value
|
|
"""
|
|
When I process postprocessing line splitting
|
|
Then specific line splitting should occur
|
|
And the lines should be restructured
|
|
|
|
Scenario: Rejects non-dict plain YAML without templates
|
|
Given I have plain YAML without templates:
|
|
"""
|
|
- item1
|
|
- item2
|
|
"""
|
|
When I load YAML content through the template engine
|
|
Then a ValueError should be raised indicating dict requirement
|
|
|
|
Scenario: Deferred loading preserves template placeholders
|
|
Given the YAML template engine is initialized for coverage
|
|
Given I have a YAML string with inline template placeholders:
|
|
"""
|
|
agent:
|
|
name: "{{ name }}"
|
|
model: "{{ model }}"
|
|
"""
|
|
When I load YAML content without context for deferred rendering
|
|
Then the deferred template should keep placeholders
|
|
And the deferred template should be a mapping with key "agent"
|
|
|
|
|
|
Scenario: Deferred loading surfaces YAML errors for invalid templates
|
|
Given I have invalid templated YAML for deferred rendering:
|
|
"""
|
|
agent:
|
|
name: {{ name
|
|
"""
|
|
When I load YAML content without context for deferred rendering
|
|
Then a YAML error should be raised for deferred loading
|
|
|
|
Scenario: Preprocess inserts indentation hints for for-loops
|
|
Given I have a YAML string with for loops requiring preprocessing:
|
|
"""
|
|
agents:
|
|
{% for item in items %}
|
|
- name: {{ item }}
|
|
{% endfor %}
|
|
"""
|
|
When I preprocess the YAML content for rendering
|
|
Then indentation hints should be present after the loop line
|
|
|
|
Scenario: Rendering with colon-heavy values triggers fallback fix
|
|
Given I have a templated YAML that renders malformed mapping:
|
|
"""
|
|
config: {{ value_with_colons }}
|
|
"""
|
|
And I have a template context with colon rich value
|
|
When I render the YAML with context
|
|
Then a YAML parsing error should be raised after attempting fixes
|
|
|
|
Scenario: Rendering simple template succeeds with merged context
|
|
Given I have a YAML string with inline Jinja2 templates:
|
|
"""
|
|
items:
|
|
{% for item in items %}
|
|
- {{ item }}
|
|
{% endfor %}
|
|
context_value: {{ context.existing }}
|
|
"""
|
|
And I have a template context with list items
|
|
When I render the YAML with context
|
|
Then the rendered YAML should be parsed into a mapping
|
|
And the rendered mapping should include loop results and merged context
|
|
|
|
Scenario: Selectattr filter fills defaults
|
|
Given I have objects with missing attributes
|
|
When I apply the selectattr filter for attribute "score" with default 0
|
|
Then the selected attributes should include defaults
|
|
|
|
Scenario: Sum and helper filters format values
|
|
Given I have numeric values for the sum filter
|
|
When I apply the sum filter and helper formatters
|
|
Then the helper filters should format output
|
|
|
|
Scenario: Analyze YAML structure skips comments and finds templates
|
|
Given I have YAML with mixed content for structure analysis:
|
|
"""
|
|
# comment
|
|
root:
|
|
value: static
|
|
{{ inline_var }}
|
|
{% for x in items %}
|
|
- name: {{ x }}
|
|
{% endfor %}
|
|
"""
|
|
When I analyze the YAML structure
|
|
Then template blocks and inline templates should be located
|
|
|
|
Scenario: Load file wrapper processes templates from disk
|
|
Given I have a temporary YAML file with template content:
|
|
"""
|
|
agent:
|
|
name: "{{ name }}"
|
|
role: static
|
|
"""
|
|
When I load the YAML file with context data
|
|
Then the file load result should merge templated values
|
|
|
|
Scenario: Rendering list template raises mapping ValueError
|
|
Given I have a templated YAML that renders to a list root:
|
|
"""
|
|
{% for item in items %}
|
|
- {{ item }}
|
|
{% endfor %}
|
|
"""
|
|
And I have a template context with list items
|
|
When I render the YAML expecting a non-mapping error
|
|
Then a ValueError should indicate rendered YAML must be a mapping
|
|
|
|
Scenario: Malformed rendered YAML triggers fallback fix path
|
|
Given I have templated YAML that renders invalid mappings:
|
|
"""
|
|
config: {{ messy_value }}
|
|
"""
|
|
And I have a messy value context for rendering
|
|
When I render the malformed YAML content
|
|
Then the parser should attempt fixes then raise YAML error
|
|
|
|
Scenario: Deferred templated list raises mapping ValueError
|
|
Given I have a deferred YAML template that becomes a list:
|
|
"""
|
|
- "{{ value }}"
|
|
"""
|
|
When I load YAML content without context for deferred rendering
|
|
Then a ValueError should be raised for non-mapping deferred templates
|
|
|
|
Scenario: Parse retry succeeds after YAML error
|
|
Given I have YAML with a placeholder causing parse retry:
|
|
"""
|
|
result: {{ value }}
|
|
"""
|
|
And I have a template context for retry parsing
|
|
When I render YAML with a transient YAML error on first parse
|
|
Then the rendering retry should yield a mapping result
|
|
|
|
Scenario: Parse retry raises ValueError when repaired YAML is not a mapping
|
|
Given I have YAML with a placeholder causing parse retry:
|
|
"""
|
|
result: {{ value }}
|
|
"""
|
|
And I have a template context for retry parsing
|
|
When rendering retry returns non-mapping after YAML error
|
|
Then a ValueError should be raised for non-mapping retry
|
|
|
|
Scenario: Fix common YAML issues splits multiple colons
|
|
Given I have inline YAML with multiple colons on one line:
|
|
"""
|
|
config: key1: val1 key2: val2
|
|
"""
|
|
When I apply the common YAML fixes
|
|
Then the multi-colon line should be split into nested entries
|
|
|
|
Scenario: Synthetic postprocess respects single-colon guard
|
|
Given I have synthetic YAML content for postprocess:
|
|
"""
|
|
config: alpha beta: gamma
|
|
"""
|
|
When I postprocess using a single-colon synthetic line
|
|
Then the synthetic postprocess should keep the line intact
|
|
|
|
Scenario: Load file without template markers
|
|
Given I have a YAML file without templates:
|
|
"""
|
|
config:
|
|
name: PlainConfig
|
|
version: 1.0
|
|
"""
|
|
When I load the YAML file without context
|
|
Then the YAML file should parse as a mapping
|
|
And the parsed YAML should include config name "PlainConfig"
|
|
|
|
Scenario: Load string without template markers
|
|
Given I have a YAML string without templates:
|
|
"""
|
|
simple:
|
|
key: value
|
|
list:
|
|
- item1
|
|
- item2
|
|
"""
|
|
When I load the string directly
|
|
Then the YAML string should parse as a mapping
|
|
And the parsed YAML string should include key value "value"
|
|
|
|
Scenario: Render context merges nested context
|
|
Given I have a template using nested context and overrides:
|
|
"""
|
|
result:
|
|
nested: "{{ context.shared }}"
|
|
explicit: "{{ value }}"
|
|
context_copy: "{{ context.explicit }}"
|
|
"""
|
|
And I have a template context with nested overrides
|
|
When I render the YAML with merged context
|
|
Then the render context should include nested and top-level values
|
|
|
|
Scenario: Utility functions are available during rendering
|
|
Given I have template using utility functions:
|
|
"""
|
|
utilities:
|
|
range_values: {{ range(3) | list }}
|
|
abs_value: {{ abs(-4) }}
|
|
round_value: {{ round(3.1415, 2) }}
|
|
"""
|
|
When I process with complete render context utilities
|
|
Then utility functions should be evaluated
|
|
|
|
Scenario: Sum filter surfaces errors for invalid sequences
|
|
Given I have non-summable values for the sum filter
|
|
When I apply the sum filter expecting an error
|
|
Then a ValueError should be raised for the sum filter
|