From c2f5d8890dce534791dfdb0a6ac1a5541da5e98d Mon Sep 17 00:00:00 2001 From: zackad Date: Sun, 18 Aug 2024 19:48:22 +0700 Subject: [PATCH] fixup! test: add test case for mappings expression --- .../__snapshots__/mappingExpression.snap.twig | 70 +++++++++++++++++++ tests/Expressions/jsfmt.spec.js | 5 +- tests/Expressions/mappingExpression.twig | 3 +- 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 tests/Expressions/__snapshots__/mappingExpression.snap.twig diff --git a/tests/Expressions/__snapshots__/mappingExpression.snap.twig b/tests/Expressions/__snapshots__/mappingExpression.snap.twig new file mode 100644 index 0000000..bcac492 --- /dev/null +++ b/tests/Expressions/__snapshots__/mappingExpression.snap.twig @@ -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 %} + +
diff --git a/tests/Expressions/jsfmt.spec.js b/tests/Expressions/jsfmt.spec.js index d98ff48..542e7e8 100644 --- a/tests/Expressions/jsfmt.spec.js +++ b/tests/Expressions/jsfmt.spec.js @@ -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); }); diff --git a/tests/Expressions/mappingExpression.twig b/tests/Expressions/mappingExpression.twig index 8aba634..e91494a 100644 --- a/tests/Expressions/mappingExpression.twig +++ b/tests/Expressions/mappingExpression.twig @@ -36,5 +36,4 @@ }, }).apply({ theme }), }) }} ->text - +>