From aca9a8088aa88197205461de3afdea93767b8070 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Fri, 8 Sep 2023 10:32:52 -0300 Subject: [PATCH] test-cases: add mixin variables test case Test that the correct tokens and syntax tree nodes are generated. Looking good so far. --- .../test/__snapshots__/index.test.js.snap | 486 ++++++++++++++++++ .../test/__snapshots__/index.test.js.snap | 213 ++++++++ test-cases/mixin-variables.pg | 14 + 3 files changed, 713 insertions(+) create mode 100644 test-cases/mixin-variables.pg diff --git a/packages/lexer/test/__snapshots__/index.test.js.snap b/packages/lexer/test/__snapshots__/index.test.js.snap index 1057af2f..baa017e1 100644 --- a/packages/lexer/test/__snapshots__/index.test.js.snap +++ b/packages/lexer/test/__snapshots__/index.test.js.snap @@ -18958,6 +18958,492 @@ exports[`mixin-hoist.pg 1`] = ` ] `; +exports[`mixin-variables.pg 1`] = ` +[ + { + "args": [ + "contents", + ], + "loc": { + "end": { + "column": 19, + "line": 1, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 1, + }, + }, + "type": "mixin", + "val": "li", + }, + { + "loc": { + "end": { + "column": 3, + "line": 2, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 2, + }, + }, + "type": "indent", + "val": 2, + }, + { + "loc": { + "end": { + "column": 5, + "line": 2, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 3, + "line": 2, + }, + }, + "type": "tag", + "val": "li", + }, + { + "loc": { + "end": { + "column": 17, + "line": 2, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 5, + "line": 2, + }, + }, + "type": "variable", + "val": "contents", + }, + { + "loc": { + "end": { + "column": 1, + "line": 4, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 4, + }, + }, + "type": "outdent", + }, + { + "loc": { + "end": { + "column": 3, + "line": 4, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 4, + }, + }, + "type": "tag", + "val": "ul", + }, + { + "loc": { + "end": { + "column": 3, + "line": 5, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 5, + }, + }, + "type": "indent", + "val": 2, + }, + { + "args": [ + "foo", + ], + "loc": { + "end": { + "column": 11, + "line": 5, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 6, + "line": 5, + }, + }, + "type": "call", + "val": "li", + }, + { + "loc": { + "end": { + "column": 3, + "line": 6, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 6, + }, + }, + "type": "newline", + }, + { + "args": [ + "bar", + ], + "loc": { + "end": { + "column": 14, + "line": 6, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 7, + "line": 6, + }, + }, + "type": "call", + "val": "li", + }, + { + "loc": { + "end": { + "column": 3, + "line": 7, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 7, + }, + }, + "type": "newline", + }, + { + "args": [ + "baz", + "quux", + ], + "loc": { + "end": { + "column": 20, + "line": 7, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 8, + "line": 7, + }, + }, + "type": "call", + "val": "li", + }, + { + "loc": { + "end": { + "column": 1, + "line": 9, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 9, + }, + }, + "type": "outdent", + }, + { + "args": [ + "name", + ], + "loc": { + "end": { + "column": 22, + "line": 9, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 9, + }, + }, + "type": "mixin", + "val": "paragraph", + }, + { + "loc": { + "end": { + "column": 3, + "line": 10, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 10, + }, + }, + "type": "indent", + "val": 2, + }, + { + "loc": { + "end": { + "column": 4, + "line": 10, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 3, + "line": 10, + }, + }, + "type": "tag", + "val": "p", + }, + { + "loc": { + "end": { + "column": 5, + "line": 10, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 4, + "line": 10, + }, + }, + "type": "dot", + }, + { + "loc": { + "end": { + "column": 5, + "line": 10, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 5, + "line": 10, + }, + }, + "type": "start-pipeless-text", + }, + { + "loc": { + "end": { + "column": 16, + "line": 11, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 5, + "line": 11, + }, + }, + "type": "text", + "val": "Hello from ", + }, + { + "loc": { + "end": { + "column": 18, + "line": 11, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 16, + "line": 11, + }, + }, + "type": "start-interpolation", + }, + { + "loc": { + "filename": "mixin-variables.pg", + "start": { + "column": 18, + "line": 11, + }, + }, + "type": "variable", + "val": "name", + }, + { + "loc": { + "end": { + "column": 23, + "line": 11, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 22, + "line": 11, + }, + }, + "type": "end-interpolation", + }, + { + "loc": { + "end": { + "column": 36, + "line": 11, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 23, + "line": 11, + }, + }, + "type": "text", + "val": " and welcome.", + }, + { + "loc": { + "end": { + "column": 5, + "line": 12, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 12, + }, + }, + "type": "newline", + }, + { + "loc": { + "end": { + "column": 42, + "line": 12, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 5, + "line": 12, + }, + }, + "type": "text", + "val": "This #{reference} should be escaped.", + }, + { + "loc": { + "end": { + "column": 1, + "line": 13, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 13, + }, + }, + "type": "newline", + }, + { + "loc": { + "end": { + "column": 1, + "line": 13, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 13, + }, + }, + "type": "text", + "val": "", + }, + { + "loc": { + "end": { + "column": 1, + "line": 13, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 13, + }, + }, + "type": "end-pipeless-text", + }, + { + "loc": { + "end": { + "column": 1, + "line": 14, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 14, + }, + }, + "type": "outdent", + }, + { + "args": [ + "pugneum", + ], + "loc": { + "end": { + "column": 20, + "line": 14, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 11, + "line": 14, + }, + }, + "type": "call", + "val": "paragraph", + }, + { + "loc": { + "end": { + "column": 1, + "line": 15, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 15, + }, + }, + "type": "newline", + }, + { + "loc": { + "end": { + "column": 1, + "line": 15, + }, + "filename": "mixin-variables.pg", + "start": { + "column": 1, + "line": 15, + }, + }, + "type": "eos", + }, +] +`; + exports[`mixin-via-include.pg 1`] = ` [ { diff --git a/packages/parser/test/__snapshots__/index.test.js.snap b/packages/parser/test/__snapshots__/index.test.js.snap index 1e19995a..75f0c1cc 100644 --- a/packages/parser/test/__snapshots__/index.test.js.snap +++ b/packages/parser/test/__snapshots__/index.test.js.snap @@ -7689,6 +7689,219 @@ exports[`mixin-hoist.pg 1`] = ` } `; +exports[`mixin-variables.pg 1`] = ` +{ + "filename": "mixin-variables.pg", + "line": 0, + "nodes": [ + { + "args": [ + "contents", + ], + "block": { + "filename": "mixin-variables.pg", + "line": 2, + "nodes": [ + { + "attributeBlocks": [], + "attrs": [], + "block": { + "filename": "mixin-variables.pg", + "line": 2, + "nodes": [ + { + "column": 5, + "filename": "mixin-variables.pg", + "line": 2, + "name": "contents", + "type": "Variable", + }, + ], + "type": "Block", + }, + "column": 3, + "filename": "mixin-variables.pg", + "isInline": false, + "line": 2, + "name": "li", + "type": "Tag", + }, + ], + "type": "Block", + }, + "call": false, + "column": 1, + "filename": "mixin-variables.pg", + "line": 1, + "name": "li", + "type": "Mixin", + }, + { + "attributeBlocks": [], + "attrs": [], + "block": { + "filename": "mixin-variables.pg", + "line": 4, + "nodes": [ + { + "args": [ + "foo", + ], + "attributeBlocks": [], + "attrs": [], + "block": null, + "call": true, + "column": 6, + "filename": "mixin-variables.pg", + "line": 5, + "name": "li", + "type": "Mixin", + }, + { + "args": [ + "bar", + ], + "attributeBlocks": [], + "attrs": [], + "block": null, + "call": true, + "column": 7, + "filename": "mixin-variables.pg", + "line": 6, + "name": "li", + "type": "Mixin", + }, + { + "args": [ + "baz", + "quux", + ], + "attributeBlocks": [], + "attrs": [], + "block": null, + "call": true, + "column": 8, + "filename": "mixin-variables.pg", + "line": 7, + "name": "li", + "type": "Mixin", + }, + ], + "type": "Block", + }, + "column": 1, + "filename": "mixin-variables.pg", + "isInline": false, + "line": 4, + "name": "ul", + "type": "Tag", + }, + { + "args": [ + "name", + ], + "block": { + "filename": "mixin-variables.pg", + "line": 10, + "nodes": [ + { + "attributeBlocks": [], + "attrs": [], + "block": { + "filename": "mixin-variables.pg", + "line": 10, + "nodes": [ + { + "column": 5, + "filename": "mixin-variables.pg", + "line": 11, + "type": "Text", + "val": "Hello from ", + }, + { + "column": 18, + "filename": "mixin-variables.pg", + "line": 11, + "name": "name", + "type": "Variable", + }, + { + "column": 23, + "filename": "mixin-variables.pg", + "line": 11, + "type": "Text", + "val": " and welcome.", + }, + { + "column": 1, + "filename": "mixin-variables.pg", + "line": 12, + "type": "Text", + "val": " +", + }, + { + "column": 5, + "filename": "mixin-variables.pg", + "line": 12, + "type": "Text", + "val": "This #{reference} should be escaped.", + }, + { + "column": 1, + "filename": "mixin-variables.pg", + "line": 13, + "type": "Text", + "val": " +", + }, + { + "column": 1, + "filename": "mixin-variables.pg", + "line": 13, + "type": "Text", + "val": "", + }, + ], + "type": "Block", + }, + "column": 3, + "filename": "mixin-variables.pg", + "isInline": false, + "line": 10, + "name": "p", + "textOnly": true, + "type": "Tag", + }, + ], + "type": "Block", + }, + "call": false, + "column": 1, + "filename": "mixin-variables.pg", + "line": 9, + "name": "paragraph", + "type": "Mixin", + }, + { + "args": [ + "pugneum", + ], + "attributeBlocks": [], + "attrs": [], + "block": null, + "call": true, + "column": 11, + "filename": "mixin-variables.pg", + "line": 14, + "name": "paragraph", + "type": "Mixin", + }, + ], + "type": "Block", +} +`; + exports[`mixin-via-include.pg 1`] = ` { "filename": "mixin-via-include.pg", diff --git a/test-cases/mixin-variables.pg b/test-cases/mixin-variables.pg new file mode 100644 index 00000000..20abcd4f --- /dev/null +++ b/test-cases/mixin-variables.pg @@ -0,0 +1,14 @@ +mixin li(contents) + li #{contents} + +ul + +li(foo) + + li('bar') + + li("baz" quux) + +mixin paragraph(name) + p. + Hello from #{name} and welcome. + This \#{reference} should be escaped. + ++paragraph(pugneum)