Skip to content

Commit

Permalink
fixup! test: add test case for mappings expression
Browse files Browse the repository at this point in the history
  • Loading branch information
zackad committed Aug 18, 2024
1 parent 6924398 commit c2f5d88
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
70 changes: 70 additions & 0 deletions tests/Expressions/__snapshots__/mappingExpression.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{# Example mappings literal expression taken from https://twig.symfony.com/doc/3.x/templates.html#literals #}
{# keys as string #}
{{
{
foo: 'foo',
bar: 'bar'
}
}}

{# keys as names (equivalent to the previous mapping) #}
{{
{
foo: 'foo',
bar: 'bar'
}
}}

{# keys as integer #}
{{
{
2: 'foo',
4: 'bar'
}
}}

{# keys can be omitted if it is the same as the variable name #}
{% set nokey = {
nokey
} %}

{% set nokey = {
no,
key
} %}
{# is equivalent to the following #}
{% set no_key = {
no: no,
key: key
} %}

{% set foo = 'foo' %}

{# keys as expressions (the expression must be enclosed into parentheses) #}
{{
{
(foo): 'foo',
(1 + 1): 'bar',
(foo ~ 'b'): 'baz'
}
}}

{% props theme = null, text = null %}

<div {{
attributes.defaults({
class: cva({
base: 'alert shadow-md',
variants: {
theme: {
info: 'alert-info',
success: 'alert-success',
warning: 'alert-warning',
error: 'alert-error'
}
}
}).apply({
theme
})
})
}}></div>
5 changes: 1 addition & 4 deletions tests/Expressions/jsfmt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ describe("Expressions", () => {
});
it("should handle mapping expressions", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "mappingExpression.twig",
formatOptions: {
twigAlwaysBreakObjects: false
}
source: "mappingExpression.twig"
});
await expect(actual).toMatchFileSnapshot(snapshotFile);
});
Expand Down
3 changes: 1 addition & 2 deletions tests/Expressions/mappingExpression.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@
},
}).apply({ theme }),
}) }}
>text
</div>
></div>

0 comments on commit c2f5d88

Please sign in to comment.