diff --git a/.gitignore b/.gitignore index b83202d..95566bc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ logs results npm-debug.log node_modules +*.actual.json +coverage diff --git a/package.json b/package.json index e79d632..c315d2c 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,16 @@ "jade-walk": "0.0.2" }, "devDependencies": { - "mocha": "*" + "istanbul": "^0.3.17", + "jade": "^1.11.0", + "jade-lexer": "0.0.8", + "jade-load": "0.0.3", + "jade-parser": "0.0.8", + "testit": "^2.0.2" }, "scripts": { - "test": "mocha -R spec" + "coverage": "istanbul cover test", + "test": "node test" }, "repository": { "type": "git", @@ -18,4 +24,4 @@ }, "author": "Forbes Lindesay", "license": "MIT" -} \ No newline at end of file +} diff --git a/test/cases/include-extends-from-root.expected.json b/test/cases/include-extends-from-root.expected.json new file mode 100644 index 0000000..db07ae6 --- /dev/null +++ b/test/cases/include-extends-from-root.expected.json @@ -0,0 +1,260 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "title", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "My Application", + "line": 3, + "filename": "auxiliary/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [], + "line": 4, + "filename": "auxiliary/layout.jade", + "name": "head", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/layout.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello", + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ], + "line": 0, + "filename": "auxiliary/include-from-root.jade", + "declaredBlocks": {} + } + ], + "line": 6, + "filename": "auxiliary/layout.jade", + "name": "content", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "auxiliary/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/layout.jade" + } + ], + "line": 0, + "filename": "auxiliary/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [], + "line": 4, + "filename": "auxiliary/layout.jade", + "name": "head", + "mode": "replace" + }, + "content": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello", + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ], + "line": 0, + "filename": "auxiliary/include-from-root.jade", + "declaredBlocks": {} + } + ], + "line": 3, + "filename": "auxiliary/extends-from-root.jade", + "name": "content", + "mode": "replace", + "parent": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello", + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ], + "line": 0, + "filename": "auxiliary/include-from-root.jade", + "declaredBlocks": {} + } + ], + "line": 6, + "filename": "auxiliary/layout.jade", + "name": "content", + "mode": "replace" + } + } + } + } + ], + "line": 0, + "filename": "include-extends-from-root.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [], + "line": 4, + "filename": "auxiliary/layout.jade", + "name": "head", + "mode": "replace" + }, + "content": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello", + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ], + "line": 0, + "filename": "auxiliary/include-from-root.jade", + "declaredBlocks": {} + } + ], + "line": 6, + "filename": "auxiliary/layout.jade", + "name": "content", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/include-extends-from-root.input.json b/test/cases/include-extends-from-root.input.json new file mode 100644 index 0000000..a1ee337 --- /dev/null +++ b/test/cases/include-extends-from-root.input.json @@ -0,0 +1,189 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "/auxiliary/extends-from-root", + "line": 1, + "filename": "include-extends-from-root.jade", + "fullPath": "auxiliary/extends-from-root.jade", + "str": "extends /auxiliary/layout\n\nblock content\n include /auxiliary/include-from-root", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "/auxiliary/layout", + "line": 1, + "filename": "auxiliary/extends-from-root.jade", + "fullPath": "auxiliary/layout.jade", + "str": "html\n head\n title My Application\n block head\n body\n block content", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "title", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "My Application", + "line": 3, + "filename": "auxiliary/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [], + "line": 4, + "filename": "auxiliary/layout.jade", + "name": "head", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/layout.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 6, + "filename": "auxiliary/layout.jade", + "name": "content", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "auxiliary/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/layout.jade" + } + ], + "line": 0, + "filename": "auxiliary/layout.jade" + } + }, + "line": 1, + "filename": "auxiliary/extends-from-root.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "/auxiliary/include-from-root", + "line": 4, + "filename": "auxiliary/extends-from-root.jade", + "fullPath": "auxiliary/include-from-root.jade", + "str": "h1 hello", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello", + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/include-from-root.jade" + } + ], + "line": 0, + "filename": "auxiliary/include-from-root.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 4, + "filename": "auxiliary/extends-from-root.jade" + } + ], + "line": 3, + "filename": "auxiliary/extends-from-root.jade", + "name": "content", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/extends-from-root.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 1, + "filename": "include-extends-from-root.jade" + } + ], + "line": 0, + "filename": "include-extends-from-root.jade" +} \ No newline at end of file diff --git a/test/cases/include-extends-of-common-template.expected.json b/test/cases/include-extends-of-common-template.expected.json new file mode 100644 index 0000000..9ffa160 --- /dev/null +++ b/test/cases/include-extends-of-common-template.expected.json @@ -0,0 +1,237 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test1", + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/empty-block.jade", + "declaredBlocks": { + "test": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test1", + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ], + "line": 3, + "filename": "auxiliary/extends-empty-block-1.jade", + "name": "test", + "mode": "replace", + "parent": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test1", + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + } + } + }, + { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test2", + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/empty-block.jade", + "declaredBlocks": { + "test": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test2", + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ], + "line": 3, + "filename": "auxiliary/extends-empty-block-2.jade", + "name": "test", + "mode": "replace", + "parent": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test2", + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + } + } + } + ], + "line": 0, + "filename": "include-extends-of-common-template.jade", + "declaredBlocks": { + "test": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test2", + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/include-extends-of-common-template.input.json b/test/cases/include-extends-of-common-template.input.json new file mode 100644 index 0000000..26d4c9a --- /dev/null +++ b/test/cases/include-extends-of-common-template.input.json @@ -0,0 +1,173 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/extends-empty-block-1", + "line": 1, + "filename": "include-extends-of-common-template.jade", + "fullPath": "auxiliary/extends-empty-block-1.jade", + "str": "extends empty-block\n\nblock test\n div test1\n\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "empty-block", + "line": 1, + "filename": "auxiliary/extends-empty-block-1.jade", + "fullPath": "auxiliary/empty-block.jade", + "str": "block test\n\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/empty-block.jade" + } + }, + "line": 1, + "filename": "auxiliary/extends-empty-block-1.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test1", + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-1.jade" + } + ], + "line": 3, + "filename": "auxiliary/extends-empty-block-1.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/extends-empty-block-1.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 1, + "filename": "include-extends-of-common-template.jade" + }, + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/extends-empty-block-2", + "line": 2, + "filename": "include-extends-of-common-template.jade", + "fullPath": "auxiliary/extends-empty-block-2.jade", + "str": "extends empty-block\n\nblock test\n div test2\n\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "empty-block", + "line": 1, + "filename": "auxiliary/extends-empty-block-2.jade", + "fullPath": "auxiliary/empty-block.jade", + "str": "block test\n\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 1, + "filename": "auxiliary/empty-block.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/empty-block.jade" + } + }, + "line": 1, + "filename": "auxiliary/extends-empty-block-2.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "test2", + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/extends-empty-block-2.jade" + } + ], + "line": 3, + "filename": "auxiliary/extends-empty-block-2.jade", + "name": "test", + "mode": "replace" + } + ], + "line": 0, + "filename": "auxiliary/extends-empty-block-2.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 2, + "filename": "include-extends-of-common-template.jade" + } + ], + "line": 0, + "filename": "include-extends-of-common-template.jade" +} \ No newline at end of file diff --git a/test/cases/include-filter-stylus.expected.json b/test/cases/include-filter-stylus.expected.json new file mode 100644 index 0000000..fbcf15d --- /dev/null +++ b/test/cases/include-filter-stylus.expected.json @@ -0,0 +1,43 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "style", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Filter", + "name": "stylus", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "@import \"test/cases/some-included\"\n" + } + ] + }, + "attrs": [] + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "\"text/css\"", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-filter-stylus.jade" + } + ], + "line": 0, + "filename": "include-filter-stylus.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-filter-stylus.input.json b/test/cases/include-filter-stylus.input.json new file mode 100644 index 0000000..37cca2a --- /dev/null +++ b/test/cases/include-filter-stylus.input.json @@ -0,0 +1,47 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "style", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "some.styl", + "line": 2, + "filename": "include-filter-stylus.jade", + "fullPath": "some.styl", + "str": "@import \"test/cases/some-included\"\n" + }, + "filter": "stylus", + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 2, + "filename": "include-filter-stylus.jade" + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "\"text/css\"", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-filter-stylus.jade" + } + ], + "line": 0, + "filename": "include-filter-stylus.jade" +} \ No newline at end of file diff --git a/test/cases/include-filter.expected.json b/test/cases/include-filter.expected.json new file mode 100644 index 0000000..89811f7 --- /dev/null +++ b/test/cases/include-filter.expected.json @@ -0,0 +1,122 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Filter", + "name": "marked", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Just _some_ markdown **tests**.\n\nWith new line.\n" + } + ] + }, + "attrs": [] + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Filter", + "name": "coffee-script", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "math =\n square: (value) -> value * value\n" + } + ] + }, + "attrs": [ + { + "name": "minify", + "val": "true", + "escaped": true + } + ] + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include-filter.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Filter", + "name": "coffee-script", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "math =\n square: (value) -> value * value\n" + } + ] + }, + "attrs": [ + { + "name": "minify", + "val": "false", + "escaped": true + } + ] + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-filter.jade" + } + ], + "line": 0, + "filename": "include-filter.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-filter.input.json b/test/cases/include-filter.input.json new file mode 100644 index 0000000..edfec4c --- /dev/null +++ b/test/cases/include-filter.input.json @@ -0,0 +1,136 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "some.md", + "line": 3, + "filename": "include-filter.jade", + "fullPath": "some.md", + "str": "Just _some_ markdown **tests**.\n\nWith new line.\n" + }, + "filter": "marked", + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 3, + "filename": "include-filter.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "include-filter-coffee.coffee", + "line": 5, + "filename": "include-filter.jade", + "fullPath": "include-filter-coffee.coffee", + "str": "math =\n square: (value) -> value * value\n" + }, + "filter": "coffee-script", + "attrs": [ + { + "name": "minify", + "val": "true", + "escaped": true + } + ], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 5, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include-filter.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "include-filter-coffee.coffee", + "line": 7, + "filename": "include-filter.jade", + "fullPath": "include-filter-coffee.coffee", + "str": "math =\n square: (value) -> value * value\n" + }, + "filter": "coffee-script", + "attrs": [ + { + "name": "minify", + "val": "false", + "escaped": true + } + ], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 7, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-filter.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-filter.jade" + } + ], + "line": 0, + "filename": "include-filter.jade" +} \ No newline at end of file diff --git a/test/cases/include-only-text-body.expected.json b/test/cases/include-only-text-body.expected.json new file mode 100644 index 0000000..dcc2eb0 --- /dev/null +++ b/test/cases/include-only-text-body.expected.json @@ -0,0 +1,27 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "The message is \"", + "line": 1, + "filename": "include-only-text-body.jade" + }, + { + "type": "Block", + "nodes": [], + "line": 2, + "filename": "include-only-text-body.jade", + "yield": true + }, + { + "type": "Text", + "val": "\"", + "line": 3, + "filename": "include-only-text-body.jade" + } + ], + "line": 0, + "filename": "include-only-text-body.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-only-text-body.input.json b/test/cases/include-only-text-body.input.json new file mode 100644 index 0000000..32273c1 --- /dev/null +++ b/test/cases/include-only-text-body.input.json @@ -0,0 +1,26 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "The message is \"", + "line": 1, + "filename": "include-only-text-body.jade" + }, + { + "type": "Block", + "nodes": [], + "line": 2, + "filename": "include-only-text-body.jade", + "yield": true + }, + { + "type": "Text", + "val": "\"", + "line": 3, + "filename": "include-only-text-body.jade" + } + ], + "line": 0, + "filename": "include-only-text-body.jade" +} \ No newline at end of file diff --git a/test/cases/include-only-text.expected.json b/test/cases/include-only-text.expected.json new file mode 100644 index 0000000..5ee52e8 --- /dev/null +++ b/test/cases/include-only-text.expected.json @@ -0,0 +1,109 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "The message is \"", + "line": 1, + "filename": "include-only-text-body.jade" + }, + { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "em", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello world", + "line": 5, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": true, + "line": 5, + "filename": "include-only-text.jade" + } + ], + "line": 5, + "filename": "include-only-text.jade" + } + ], + "line": 2, + "filename": "include-only-text-body.jade", + "yield": true + }, + { + "type": "Text", + "val": "\"", + "line": 3, + "filename": "include-only-text-body.jade" + } + ], + "line": 0, + "filename": "include-only-text-body.jade", + "declaredBlocks": {} + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-only-text.jade" + } + ], + "line": 0, + "filename": "include-only-text.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-only-text.input.json b/test/cases/include-only-text.input.json new file mode 100644 index 0000000..4e28794 --- /dev/null +++ b/test/cases/include-only-text.input.json @@ -0,0 +1,120 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "include-only-text-body", + "line": 4, + "filename": "include-only-text.jade", + "fullPath": "include-only-text-body.jade", + "str": "| The message is \"\nyield\n| \"\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "The message is \"", + "line": 1, + "filename": "include-only-text-body.jade" + }, + { + "type": "Block", + "nodes": [], + "line": 2, + "filename": "include-only-text-body.jade", + "yield": true + }, + { + "type": "Text", + "val": "\"", + "line": 3, + "filename": "include-only-text-body.jade" + } + ], + "line": 0, + "filename": "include-only-text-body.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "em", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "hello world", + "line": 5, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": true, + "line": 5, + "filename": "include-only-text.jade" + } + ], + "line": 5, + "filename": "include-only-text.jade" + }, + "line": 4, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-only-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-only-text.jade" + } + ], + "line": 0, + "filename": "include-only-text.jade" +} \ No newline at end of file diff --git a/test/cases/include-with-text-head.expected.json b/test/cases/include-with-text-head.expected.json new file mode 100644 index 0000000..553221c --- /dev/null +++ b/test/cases/include-with-text-head.expected.json @@ -0,0 +1,50 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "alert('hello world');", + "line": 3 + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "'text/javascript'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-with-text-head.jade", + "textOnly": true + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text-head.jade" + } + ], + "line": 0, + "filename": "include-with-text-head.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-with-text-head.input.json b/test/cases/include-with-text-head.input.json new file mode 100644 index 0000000..ef2df48 --- /dev/null +++ b/test/cases/include-with-text-head.input.json @@ -0,0 +1,49 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "alert('hello world');", + "line": 3 + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "'text/javascript'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-with-text-head.jade", + "textOnly": true + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text-head.jade" + } + ], + "line": 0, + "filename": "include-with-text-head.jade" +} \ No newline at end of file diff --git a/test/cases/include-with-text.expected.json b/test/cases/include-with-text.expected.json new file mode 100644 index 0000000..fd5c07a --- /dev/null +++ b/test/cases/include-with-text.expected.json @@ -0,0 +1,120 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "alert('hello world');", + "line": 3 + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "'text/javascript'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-with-text-head.jade", + "textOnly": true + }, + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include-with-text.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include-with-text.jade" + } + ], + "line": 3, + "filename": "include-with-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text-head.jade" + } + ], + "line": 0, + "filename": "include-with-text-head.jade", + "declaredBlocks": {} + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text.jade" + } + ], + "line": 0, + "filename": "include-with-text.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include-with-text.input.json b/test/cases/include-with-text.input.json new file mode 100644 index 0000000..afd76b7 --- /dev/null +++ b/test/cases/include-with-text.input.json @@ -0,0 +1,132 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "include-with-text-head", + "line": 2, + "filename": "include-with-text.jade", + "fullPath": "include-with-text-head.jade", + "str": "head\n script(type='text/javascript').\n alert('hello world');\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "alert('hello world');", + "line": 3 + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "'text/javascript'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "include-with-text-head.jade", + "textOnly": true + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text-head.jade" + } + ], + "line": 0, + "filename": "include-with-text-head.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include-with-text.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include-with-text.jade" + } + ], + "line": 3, + "filename": "include-with-text.jade" + }, + "line": 2, + "filename": "include-with-text.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include-with-text.jade" + } + ], + "line": 0, + "filename": "include-with-text.jade" +} \ No newline at end of file diff --git a/test/cases/include.script.expected.json b/test/cases/include.script.expected.json new file mode 100644 index 0000000..6d344c5 --- /dev/null +++ b/test/cases/include.script.expected.json @@ -0,0 +1,104 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "{{name}}", + "line": 2, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/pet.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "{{name}} is a {{species}} that is {{age}} old", + "line": 3, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'pet'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/pet.jade" + } + ], + "line": 0, + "filename": "auxiliary/pet.jade", + "declaredBlocks": {} + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'pet-template'", + "escaped": false + }, + { + "name": "type", + "val": "'text/x-template'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include.script.jade" + } + ], + "line": 0, + "filename": "include.script.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include.script.input.json b/test/cases/include.script.input.json new file mode 100644 index 0000000..49d638f --- /dev/null +++ b/test/cases/include.script.input.json @@ -0,0 +1,120 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/pet", + "line": 2, + "filename": "include.script.jade", + "fullPath": "auxiliary/pet.jade", + "str": ".pet\n h1 {{name}}\n p {{name}} is a {{species}} that is {{age}} old", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "{{name}}", + "line": 2, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/pet.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "{{name}} is a {{species}} that is {{age}} old", + "line": 3, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/pet.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'pet'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/pet.jade" + } + ], + "line": 0, + "filename": "auxiliary/pet.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 2, + "filename": "include.script.jade" + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'pet-template'", + "escaped": false + }, + { + "name": "type", + "val": "'text/x-template'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "include.script.jade" + } + ], + "line": 0, + "filename": "include.script.jade" +} \ No newline at end of file diff --git a/test/cases/include.yield.nested.expected.json b/test/cases/include.yield.nested.expected.json new file mode 100644 index 0000000..cbc80ed --- /dev/null +++ b/test/cases/include.yield.nested.expected.json @@ -0,0 +1,227 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "title", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Page", + "line": 5, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "some content", + "line": 3, + "filename": "include.yield.nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include.yield.nested.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "and some more", + "line": 4, + "filename": "include.yield.nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include.yield.nested.jade" + } + ], + "line": 3, + "filename": "include.yield.nested.jade" + } + ], + "line": 8, + "filename": "auxiliary/yield-nested.jade", + "yield": true + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'content-wrapper'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "stuff", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 10, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'footer'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/yield-nested.jade" + } + ], + "line": 0, + "filename": "auxiliary/yield-nested.jade", + "declaredBlocks": {} + } + ], + "line": 0, + "filename": "include.yield.nested.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/include.yield.nested.input.json b/test/cases/include.yield.nested.input.json new file mode 100644 index 0000000..31d0b8b --- /dev/null +++ b/test/cases/include.yield.nested.input.json @@ -0,0 +1,238 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/yield-nested", + "line": 2, + "filename": "include.yield.nested.jade", + "fullPath": "auxiliary/yield-nested.jade", + "str": "html\n head\n title\n body\n h1 Page\n #content\n #content-wrapper\n yield\n #footer\n stuff", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "title", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "h1", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Page", + "line": 5, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [], + "line": 8, + "filename": "auxiliary/yield-nested.jade", + "yield": true + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'content-wrapper'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "auxiliary/yield-nested.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "stuff", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 10, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [ + { + "name": "id", + "val": "'footer'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "auxiliary/yield-nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "auxiliary/yield-nested.jade" + } + ], + "line": 0, + "filename": "auxiliary/yield-nested.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "some content", + "line": 3, + "filename": "include.yield.nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "include.yield.nested.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "and some more", + "line": 4, + "filename": "include.yield.nested.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "include.yield.nested.jade" + } + ], + "line": 3, + "filename": "include.yield.nested.jade" + }, + "line": 2, + "filename": "include.yield.nested.jade" + } + ], + "line": 0, + "filename": "include.yield.nested.jade" +} \ No newline at end of file diff --git a/test/cases/includes-with-ext-js.expected.json b/test/cases/includes-with-ext-js.expected.json new file mode 100644 index 0000000..ddd138c --- /dev/null +++ b/test/cases/includes-with-ext-js.expected.json @@ -0,0 +1,42 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "pre", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "code", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "var x = \"\\n here is some \\n new lined text\";\n" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": true, + "line": 2, + "filename": "includes-with-ext-js.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "includes-with-ext-js.jade" + } + ], + "line": 0, + "filename": "includes-with-ext-js.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/includes-with-ext-js.input.json b/test/cases/includes-with-ext-js.input.json new file mode 100644 index 0000000..7146211 --- /dev/null +++ b/test/cases/includes-with-ext-js.input.json @@ -0,0 +1,55 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "pre", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "code", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "javascript-new-lines.js", + "line": 3, + "filename": "includes-with-ext-js.jade", + "fullPath": "javascript-new-lines.js", + "str": "var x = \"\\n here is some \\n new lined text\";\n" + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 3, + "filename": "includes-with-ext-js.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": true, + "line": 2, + "filename": "includes-with-ext-js.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 1, + "filename": "includes-with-ext-js.jade" + } + ], + "line": 0, + "filename": "includes-with-ext-js.jade" +} \ No newline at end of file diff --git a/test/cases/includes.expected.json b/test/cases/includes.expected.json new file mode 100644 index 0000000..f58efc0 --- /dev/null +++ b/test/cases/includes.expected.json @@ -0,0 +1,120 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Block", + "nodes": [ + { + "type": "Mixin", + "name": "foo", + "args": null, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "bar", + "line": 3, + "filename": "auxiliary/mixins.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/mixins.jade" + } + ], + "line": 3, + "filename": "auxiliary/mixins.jade" + }, + "call": false, + "line": 2, + "filename": "auxiliary/mixins.jade" + } + ], + "line": 0, + "filename": "auxiliary/mixins.jade", + "declaredBlocks": {} + }, + { + "type": "Mixin", + "name": "foo", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 4, + "filename": "includes.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "

:)

" + }, + { + "type": "Text", + "val": "" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Filter", + "name": "verbatim", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "var STRING_SUBSTITUTIONS = { // table of character substitutions\n '\\t': '\\\\t',\n '\\r': '\\\\r',\n '\\n': '\\\\n',\n '\"' : '\\\\\"',\n '\\\\': '\\\\\\\\'\n};" + } + ] + }, + "attrs": [] + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "\"text/javascript\"", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "includes.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "includes.jade" + } + ], + "line": 0, + "filename": "includes.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/cases/includes.input.json b/test/cases/includes.input.json new file mode 100644 index 0000000..cc47898 --- /dev/null +++ b/test/cases/includes.input.json @@ -0,0 +1,169 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/mixins", + "line": 2, + "filename": "includes.jade", + "fullPath": "auxiliary/mixins.jade", + "str": "\nmixin foo()\n p bar", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Mixin", + "name": "foo", + "args": null, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "bar", + "line": 3, + "filename": "auxiliary/mixins.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "auxiliary/mixins.jade" + } + ], + "line": 3, + "filename": "auxiliary/mixins.jade" + }, + "call": false, + "line": 2, + "filename": "auxiliary/mixins.jade" + } + ], + "line": 0, + "filename": "auxiliary/mixins.jade" + } + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 2, + "filename": "includes.jade" + }, + { + "type": "Mixin", + "name": "foo", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 4, + "filename": "includes.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/smile.html", + "line": 7, + "filename": "includes.jade", + "fullPath": "auxiliary/smile.html", + "str": "

:)

" + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 7, + "filename": "includes.jade" + }, + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/escapes.html", + "line": 8, + "filename": "includes.jade", + "fullPath": "auxiliary/escapes.html", + "str": "" + }, + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 8, + "filename": "includes.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Include", + "file": { + "type": "FileReference", + "path": "auxiliary/includable.js", + "line": 10, + "filename": "includes.jade", + "fullPath": "auxiliary/includable.js", + "str": "var STRING_SUBSTITUTIONS = { // table of character substitutions\n '\\t': '\\\\t',\n '\\r': '\\\\r',\n '\\n': '\\\\n',\n '\"' : '\\\\\"',\n '\\\\': '\\\\\\\\'\n};" + }, + "filter": "verbatim", + "attrs": [], + "block": { + "type": "Block", + "nodes": [] + }, + "line": 10, + "filename": "includes.jade" + } + ] + }, + "attrs": [ + { + "name": "type", + "val": "\"text/javascript\"", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "includes.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "includes.jade" + } + ], + "line": 0, + "filename": "includes.jade" +} \ No newline at end of file diff --git a/test/cases/layout.append.expected.json b/test/cases/layout.append.expected.json new file mode 100644 index 0000000..842cea0 --- /dev/null +++ b/test/cases/layout.append.expected.json @@ -0,0 +1,273 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.jade" + } + ], + "line": 3, + "filename": "../fixtures/append/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/append/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/append/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/append/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.jade" + } + ], + "line": 3, + "filename": "../fixtures/append/layout.jade", + "name": "head", + "mode": "replace" + }, + "body": { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append/layout.jade", + "name": "body", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/layout.append.input.json b/test/cases/layout.append.input.json new file mode 100644 index 0000000..83e1a5c --- /dev/null +++ b/test/cases/layout.append.input.json @@ -0,0 +1,212 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/append/app-layout", + "line": 2, + "filename": "layout.append.jade", + "fullPath": "../fixtures/append/app-layout.jade", + "str": "\nextends layout\n\nblock append head\n script(src='app.js')", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "layout", + "line": 2, + "filename": "../fixtures/append/app-layout.jade", + "fullPath": "../fixtures/append/layout.jade", + "str": "\nhtml\n block head\n script(src='vendor/jquery.js')\n script(src='vendor/caustic.js')\n body\n block body", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/append/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/append/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/append/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/append/layout.jade" + } + }, + "line": 2, + "filename": "../fixtures/append/app-layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append/app-layout.jade" + } + ], + "line": 4, + "filename": "../fixtures/append/app-layout.jade", + "name": "head", + "mode": "append" + } + ], + "line": 0, + "filename": "../fixtures/append/app-layout.jade" + } + }, + "line": 2, + "filename": "layout.append.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.jade" + } + ], + "line": 4, + "filename": "layout.append.jade", + "name": "head", + "mode": "append" + } + ], + "line": 0, + "filename": "layout.append.jade" +} \ No newline at end of file diff --git a/test/cases/layout.append.without-block.expected.json b/test/cases/layout.append.without-block.expected.json new file mode 100644 index 0000000..8c4b68f --- /dev/null +++ b/test/cases/layout.append.without-block.expected.json @@ -0,0 +1,273 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.without-block.jade" + } + ], + "line": 3, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/append-without-block/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/append-without-block/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/append-without-block/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.without-block.jade" + } + ], + "line": 3, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + "body": { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/layout.append.without-block.input.json b/test/cases/layout.append.without-block.input.json new file mode 100644 index 0000000..a682116 --- /dev/null +++ b/test/cases/layout.append.without-block.input.json @@ -0,0 +1,212 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/append-without-block/app-layout", + "line": 2, + "filename": "layout.append.without-block.jade", + "fullPath": "../fixtures/append-without-block/app-layout.jade", + "str": "\nextends layout\n\nappend head\n script(src='app.js')", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "layout", + "line": 2, + "filename": "../fixtures/append-without-block/app-layout.jade", + "fullPath": "../fixtures/append-without-block/layout.jade", + "str": "\nhtml\n block head\n script(src='vendor/jquery.js')\n script(src='vendor/caustic.js')\n body\n block body", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/append-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/append-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/append-without-block/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/append-without-block/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/append-without-block/layout.jade" + } + }, + "line": 2, + "filename": "../fixtures/append-without-block/app-layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/append-without-block/app-layout.jade" + } + ], + "line": 4, + "filename": "../fixtures/append-without-block/app-layout.jade", + "name": "head", + "mode": "append" + } + ], + "line": 0, + "filename": "../fixtures/append-without-block/app-layout.jade" + } + }, + "line": 2, + "filename": "layout.append.without-block.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.append.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.append.without-block.jade" + } + ], + "line": 4, + "filename": "layout.append.without-block.jade", + "name": "head", + "mode": "append" + } + ], + "line": 0, + "filename": "layout.append.without-block.jade" +} \ No newline at end of file diff --git a/test/cases/layout.multi.append.prepend.block.expected.json b/test/cases/layout.multi.append.prepend.block.expected.json new file mode 100644 index 0000000..a44a2b3 --- /dev/null +++ b/test/cases/layout.multi.append.prepend.block.expected.json @@ -0,0 +1,508 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last prepend must appear at top", + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something prepended to content", + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Defined content", + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something appended to content", + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last append must be most last", + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 1, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "content", + "mode": "replace" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 19, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/root.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 16, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "head", + "mode": "replace" + } + ], + "line": 0, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "declaredBlocks": { + "content": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Defined content", + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ], + "line": 3, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade", + "name": "content", + "mode": "replace", + "parent": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last prepend must appear at top", + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something prepended to content", + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Defined content", + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something appended to content", + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last append must be most last", + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 1, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "content", + "mode": "replace" + } + }, + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 19, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/root.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 16, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "head", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/layout.multi.append.prepend.block.input.json b/test/cases/layout.multi.append.prepend.block.input.json new file mode 100644 index 0000000..80839d6 --- /dev/null +++ b/test/cases/layout.multi.append.prepend.block.input.json @@ -0,0 +1,348 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/multi-append-prepend-block/redefine", + "line": 1, + "filename": "layout.multi.append.prepend.block.jade", + "fullPath": "../fixtures/multi-append-prepend-block/redefine.jade", + "str": "extends root\n\nblock content\n\t.content\n\t\t| Defined content", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "root", + "line": 1, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade", + "fullPath": "../fixtures/multi-append-prepend-block/root.jade", + "str": "block content\n\t| default content\n\nblock head\n\tscript(src='/app.js')", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Text", + "val": "default content", + "line": 2, + "filename": "../fixtures/multi-append-prepend-block/root.jade" + } + ], + "line": 1, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "content", + "mode": "replace" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'/app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/root.jade" + } + ], + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/root.jade", + "name": "head", + "mode": "replace" + } + ], + "line": 0, + "filename": "../fixtures/multi-append-prepend-block/root.jade" + } + }, + "line": 1, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "div", + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Defined content", + "line": 5, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'content'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + ], + "line": 3, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade", + "name": "content", + "mode": "replace" + } + ], + "line": 0, + "filename": "../fixtures/multi-append-prepend-block/redefine.jade" + } + }, + "line": 1, + "filename": "layout.multi.append.prepend.block.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something appended to content", + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 3, + "filename": "layout.multi.append.prepend.block.jade", + "name": "content", + "mode": "append" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Something prepended to content", + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'first'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 6, + "filename": "layout.multi.append.prepend.block.jade", + "name": "content", + "mode": "prepend" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last append must be most last", + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'append'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 10, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 9, + "filename": "layout.multi.append.prepend.block.jade", + "name": "content", + "mode": "append" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Last prepend must appear at top", + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + } + ] + }, + "attrs": [ + { + "name": "class", + "val": "'last'", + "escaped": false + }, + { + "name": "class", + "val": "'prepend'", + "escaped": false + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 13, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 12, + "filename": "layout.multi.append.prepend.block.jade", + "name": "content", + "mode": "prepend" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 16, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 15, + "filename": "layout.multi.append.prepend.block.jade", + "name": "head", + "mode": "append" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 19, + "filename": "layout.multi.append.prepend.block.jade" + } + ], + "line": 18, + "filename": "layout.multi.append.prepend.block.jade", + "name": "head", + "mode": "prepend" + } + ], + "line": 0, + "filename": "layout.multi.append.prepend.block.jade" +} \ No newline at end of file diff --git a/test/cases/layout.prepend.expected.json b/test/cases/layout.prepend.expected.json new file mode 100644 index 0000000..340d882 --- /dev/null +++ b/test/cases/layout.prepend.expected.json @@ -0,0 +1,273 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/prepend/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/prepend/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/prepend/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend/layout.jade", + "name": "head", + "mode": "replace" + }, + "body": { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend/layout.jade", + "name": "body", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/layout.prepend.input.json b/test/cases/layout.prepend.input.json new file mode 100644 index 0000000..c98267e --- /dev/null +++ b/test/cases/layout.prepend.input.json @@ -0,0 +1,212 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/prepend/app-layout", + "line": 2, + "filename": "layout.prepend.jade", + "fullPath": "../fixtures/prepend/app-layout.jade", + "str": "\nextends layout\n\nblock prepend head\n script(src='app.js')", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "layout", + "line": 2, + "filename": "../fixtures/prepend/app-layout.jade", + "fullPath": "../fixtures/prepend/layout.jade", + "str": "\nhtml\n block head\n script(src='vendor/jquery.js')\n script(src='vendor/caustic.js')\n body\n block body", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/prepend/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/prepend/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/prepend/layout.jade" + } + }, + "line": 2, + "filename": "../fixtures/prepend/app-layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend/app-layout.jade" + } + ], + "line": 4, + "filename": "../fixtures/prepend/app-layout.jade", + "name": "head", + "mode": "prepend" + } + ], + "line": 0, + "filename": "../fixtures/prepend/app-layout.jade" + } + }, + "line": 2, + "filename": "layout.prepend.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.jade" + } + ], + "line": 4, + "filename": "layout.prepend.jade", + "name": "head", + "mode": "prepend" + } + ], + "line": 0, + "filename": "layout.prepend.jade" +} \ No newline at end of file diff --git a/test/cases/layout.prepend.without-block.expected.json b/test/cases/layout.prepend.without-block.expected.json new file mode 100644 index 0000000..596756d --- /dev/null +++ b/test/cases/layout.prepend.without-block.expected.json @@ -0,0 +1,273 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/prepend-without-block/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/app-layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + "body": { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + } +} \ No newline at end of file diff --git a/test/cases/layout.prepend.without-block.input.json b/test/cases/layout.prepend.without-block.input.json new file mode 100644 index 0000000..d4074c8 --- /dev/null +++ b/test/cases/layout.prepend.without-block.input.json @@ -0,0 +1,212 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/prepend-without-block/app-layout", + "line": 2, + "filename": "layout.prepend.without-block.jade", + "fullPath": "../fixtures/prepend-without-block/app-layout.jade", + "str": "\nextends layout\n\nprepend head\n script(src='app.js')", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "layout", + "line": 2, + "filename": "../fixtures/prepend-without-block/app-layout.jade", + "fullPath": "../fixtures/prepend-without-block/layout.jade", + "str": "\nhtml\n block head\n script(src='vendor/jquery.js')\n script(src='vendor/caustic.js')\n body\n block body", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/jquery.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/prepend-without-block/layout.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'vendor/caustic.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ], + "line": 3, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "head", + "mode": "replace" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 7, + "filename": "../fixtures/prepend-without-block/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 2, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/prepend-without-block/layout.jade" + } + }, + "line": 2, + "filename": "../fixtures/prepend-without-block/app-layout.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'app.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "../fixtures/prepend-without-block/app-layout.jade" + } + ], + "line": 4, + "filename": "../fixtures/prepend-without-block/app-layout.jade", + "name": "head", + "mode": "prepend" + } + ], + "line": 0, + "filename": "../fixtures/prepend-without-block/app-layout.jade" + } + }, + "line": 2, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'foo.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 5, + "filename": "layout.prepend.without-block.jade" + }, + { + "type": "Tag", + "name": "script", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [] + }, + "attrs": [ + { + "name": "src", + "val": "'bar.js'", + "escaped": true + } + ], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "layout.prepend.without-block.jade" + } + ], + "line": 4, + "filename": "layout.prepend.without-block.jade", + "name": "head", + "mode": "prepend" + } + ], + "line": 0, + "filename": "layout.prepend.without-block.jade" +} \ No newline at end of file diff --git a/test/common.js b/test/common.js new file mode 100644 index 0000000..e7c998c --- /dev/null +++ b/test/common.js @@ -0,0 +1,10 @@ +var assert = require('assert'); + +exports.prettyStringify = function prettyStringify (obj) { + return JSON.stringify(obj, null, ' '); +} + +// TODO: investigate if/how assert.deepEqual is buggy +exports.assertObjEqual = function assertObjEqual (a, b) { + assert.equal(JSON.stringify(a), JSON.stringify(b)); +} diff --git a/test/errors-src/child-with-tags.jade b/test/errors-src/child-with-tags.jade new file mode 100644 index 0000000..fb439dd --- /dev/null +++ b/test/errors-src/child-with-tags.jade @@ -0,0 +1,6 @@ +extend ../fixtures/layout + +block body + p Hello world! + +p BAD!!! diff --git a/test/errors/child-with-tags.input.json b/test/errors/child-with-tags.input.json new file mode 100644 index 0000000..1c9b29c --- /dev/null +++ b/test/errors/child-with-tags.input.json @@ -0,0 +1,152 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/layout", + "line": 1, + "filename": "child-with-tags.jade", + "fullPath": "../fixtures/layout.jade", + "str": "doctype\n\nhtml\n head\n block head\n Hello world!\n body\n block body\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Doctype", + "line": 1, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Text", + "val": "Hello world!", + "filename": "../fixtures/layout.jade", + "line": 6, + "isHtml": true + } + ], + "line": 5, + "filename": "../fixtures/layout.jade", + "name": "head", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 8, + "filename": "../fixtures/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "../fixtures/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "../fixtures/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/layout.jade" + } + }, + "line": 1, + "filename": "child-with-tags.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Hello world!", + "line": 4, + "filename": "child-with-tags.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "child-with-tags.jade" + } + ], + "line": 3, + "filename": "child-with-tags.jade", + "name": "body", + "mode": "replace" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "BAD!!!", + "line": 6, + "filename": "child-with-tags.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 6, + "filename": "child-with-tags.jade" + } + ], + "line": 0, + "filename": "child-with-tags.jade" +} \ No newline at end of file diff --git a/test/fixtures/layout.jade b/test/fixtures/layout.jade new file mode 100644 index 0000000..aaa3c63 --- /dev/null +++ b/test/fixtures/layout.jade @@ -0,0 +1,8 @@ +doctype + +html + head + block head + Hello world! + body + block body diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..37a1275 --- /dev/null +++ b/test/index.js @@ -0,0 +1,42 @@ +var assert = require('assert'); +var fs = require('fs'); +var test = require('testit'); +var link = require('../'); +var prettyStringify = require('./common').prettyStringify; +var assertObjEqual = require('./common').assertObjEqual; + +function testDir (dir) { + fs.readdirSync(dir).forEach(function (name) { + if (!/\.input\.json$/.test(name)) return; + test(name, function () { + var actual = link(JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8'))); + fs.writeFileSync(dir + '/' + name.replace(/\.input\.json$/, '.actual.json'), prettyStringify(actual)); + var expected = JSON.parse(fs.readFileSync(dir + '/' + name.replace(/\.input\.json$/, '.expected.json'), 'utf8')); + assertObjEqual(actual, expected); + }); + }); +} + +function testDirError (dir) { + fs.readdirSync(dir).forEach(function (name) { + if (!/\.input\.json$/.test(name)) return; + test(name, function () { + var input = JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8')); + assert.throws(function () { + link(input); + }); + }); + }); +} + +test('cases from jade', function () { + testDir(__dirname + '/cases'); +}); + +test('special cases', function () { + testDir(__dirname + '/special-cases'); +}); + +test('error handling', function () { + testDirError(__dirname + '/errors'); +}); diff --git a/test/special-cases-src/empty.jade b/test/special-cases-src/empty.jade new file mode 100644 index 0000000..e69de29 diff --git a/test/special-cases-src/extending-empty.jade b/test/special-cases-src/extending-empty.jade new file mode 100644 index 0000000..141f46c --- /dev/null +++ b/test/special-cases-src/extending-empty.jade @@ -0,0 +1 @@ +extend empty diff --git a/test/special-cases-src/root-mixin.jade b/test/special-cases-src/root-mixin.jade new file mode 100644 index 0000000..b8ed01c --- /dev/null +++ b/test/special-cases-src/root-mixin.jade @@ -0,0 +1,9 @@ +extend ../fixtures/layout + +mixin myMixin + p Hello world + +block body + p Before + +myMixin + p After diff --git a/test/special-cases/empty.expected.json b/test/special-cases/empty.expected.json new file mode 100644 index 0000000..99f5a73 --- /dev/null +++ b/test/special-cases/empty.expected.json @@ -0,0 +1,7 @@ +{ + "type": "Block", + "nodes": [], + "line": 0, + "filename": "empty.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/special-cases/empty.input.json b/test/special-cases/empty.input.json new file mode 100644 index 0000000..dc4072c --- /dev/null +++ b/test/special-cases/empty.input.json @@ -0,0 +1,6 @@ +{ + "type": "Block", + "nodes": [], + "line": 0, + "filename": "empty.jade" +} \ No newline at end of file diff --git a/test/special-cases/extending-empty.expected.json b/test/special-cases/extending-empty.expected.json new file mode 100644 index 0000000..99f5a73 --- /dev/null +++ b/test/special-cases/extending-empty.expected.json @@ -0,0 +1,7 @@ +{ + "type": "Block", + "nodes": [], + "line": 0, + "filename": "empty.jade", + "declaredBlocks": {} +} \ No newline at end of file diff --git a/test/special-cases/extending-empty.input.json b/test/special-cases/extending-empty.input.json new file mode 100644 index 0000000..0d2c3e1 --- /dev/null +++ b/test/special-cases/extending-empty.input.json @@ -0,0 +1,26 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "empty", + "line": 1, + "filename": "extending-empty.jade", + "fullPath": "empty.jade", + "str": "", + "ast": { + "type": "Block", + "nodes": [], + "line": 0, + "filename": "empty.jade" + } + }, + "line": 1, + "filename": "extending-empty.jade" + } + ], + "line": 0, + "filename": "extending-empty.jade" +} \ No newline at end of file diff --git a/test/special-cases/root-mixin.expected.json b/test/special-cases/root-mixin.expected.json new file mode 100644 index 0000000..7e0c5a3 --- /dev/null +++ b/test/special-cases/root-mixin.expected.json @@ -0,0 +1,310 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Mixin", + "name": "myMixin", + "args": null, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Hello world", + "line": 4, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "root-mixin.jade" + } + ], + "line": 4, + "filename": "root-mixin.jade" + }, + "call": false, + "line": 3, + "filename": "root-mixin.jade" + }, + { + "type": "Doctype", + "line": 1, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Text", + "val": "Hello world!", + "filename": "../fixtures/layout.jade", + "line": 6, + "isHtml": true + } + ], + "line": 5, + "filename": "../fixtures/layout.jade", + "name": "head", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Before", + "line": 7, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "root-mixin.jade" + }, + { + "type": "Mixin", + "name": "myMixin", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 8, + "filename": "root-mixin.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "After", + "line": 9, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "root-mixin.jade" + } + ], + "line": 8, + "filename": "../fixtures/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "../fixtures/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "../fixtures/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/layout.jade", + "declaredBlocks": { + "head": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Text", + "val": "Hello world!", + "filename": "../fixtures/layout.jade", + "line": 6, + "isHtml": true + } + ], + "line": 5, + "filename": "../fixtures/layout.jade", + "name": "head", + "mode": "replace" + }, + "body": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Before", + "line": 7, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "root-mixin.jade" + }, + { + "type": "Mixin", + "name": "myMixin", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 8, + "filename": "root-mixin.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "After", + "line": 9, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "root-mixin.jade" + } + ], + "line": 6, + "filename": "root-mixin.jade", + "name": "body", + "mode": "replace", + "parent": { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Before", + "line": 7, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "root-mixin.jade" + }, + { + "type": "Mixin", + "name": "myMixin", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 8, + "filename": "root-mixin.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "After", + "line": 9, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "root-mixin.jade" + } + ], + "line": 8, + "filename": "../fixtures/layout.jade", + "name": "body", + "mode": "replace" + } + } + } +} \ No newline at end of file diff --git a/test/special-cases/root-mixin.input.json b/test/special-cases/root-mixin.input.json new file mode 100644 index 0000000..76c8a58 --- /dev/null +++ b/test/special-cases/root-mixin.input.json @@ -0,0 +1,198 @@ +{ + "type": "Block", + "nodes": [ + { + "type": "Extends", + "file": { + "type": "FileReference", + "path": "../fixtures/layout", + "line": 1, + "filename": "root-mixin.jade", + "fullPath": "../fixtures/layout.jade", + "str": "doctype\n\nhtml\n head\n block head\n Hello world!\n body\n block body\n", + "ast": { + "type": "Block", + "nodes": [ + { + "type": "Doctype", + "line": 1, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "html", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "head", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Text", + "val": "Hello world!", + "filename": "../fixtures/layout.jade", + "line": 6, + "isHtml": true + } + ], + "line": 5, + "filename": "../fixtures/layout.jade", + "name": "head", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "../fixtures/layout.jade" + }, + { + "type": "Tag", + "name": "body", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "NamedBlock", + "nodes": [], + "line": 8, + "filename": "../fixtures/layout.jade", + "name": "body", + "mode": "replace" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "../fixtures/layout.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 3, + "filename": "../fixtures/layout.jade" + } + ], + "line": 0, + "filename": "../fixtures/layout.jade" + } + }, + "line": 1, + "filename": "root-mixin.jade" + }, + { + "type": "Mixin", + "name": "myMixin", + "args": null, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Hello world", + "line": 4, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 4, + "filename": "root-mixin.jade" + } + ], + "line": 4, + "filename": "root-mixin.jade" + }, + "call": false, + "line": 3, + "filename": "root-mixin.jade" + }, + { + "type": "NamedBlock", + "nodes": [ + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "Before", + "line": 7, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 7, + "filename": "root-mixin.jade" + }, + { + "type": "Mixin", + "name": "myMixin", + "block": null, + "call": true, + "attrs": [], + "attributeBlocks": [], + "line": 8, + "filename": "root-mixin.jade" + }, + { + "type": "Tag", + "name": "p", + "selfClosing": false, + "block": { + "type": "Block", + "nodes": [ + { + "type": "Text", + "val": "After", + "line": 9, + "filename": "root-mixin.jade" + } + ] + }, + "attrs": [], + "attributeBlocks": [], + "isInline": false, + "line": 9, + "filename": "root-mixin.jade" + } + ], + "line": 6, + "filename": "root-mixin.jade", + "name": "body", + "mode": "replace" + } + ], + "line": 0, + "filename": "root-mixin.jade" +} \ No newline at end of file diff --git a/test/update-test-cases.js b/test/update-test-cases.js new file mode 100644 index 0000000..a7b8011 --- /dev/null +++ b/test/update-test-cases.js @@ -0,0 +1,158 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); +var lex = require('jade-lexer'); +var parse = require('jade-parser'); +var load = require('jade-load'); +var link = require('../'); +var prettyStringify = require('./common').prettyStringify; +var assertObjEqual = require('./common').assertObjEqual; + +function removeItem (array, itemToRemove) { + return array.filter(function (item) { + return item !== itemToRemove; + }); +} + +function updateDir (outDir, originalFileDir, inputFiles) { + originalFileDir = originalFileDir || outDir; + inputFiles = inputFiles || fs.readdirSync(originalFileDir).filter(function (name) { + return /\.jade$/.test(name); + }); + var existing = fs.readdirSync(outDir).filter(function (name) { + return /\.input\.json$/.test(name); + }); + var existingExpected = fs.readdirSync(outDir).filter(function (name) { + return /\.expected\.json$/.test(name); + }); + inputFiles.forEach(update); + + function update (jadeName) { + var name = jadeName.replace(/\.jade$/, ''); + var inputName = name + '.input.json'; + var expectedName = name + '.expected.json'; + var alreadyExists = existing.indexOf(inputName) !== -1 && existingExpected.indexOf(expectedName) !== -1; + var actualInputAst = load.file(jadeName, { + lex: lex, + parse: parse, + resolve: function (filename, source) { + filename = filename.trim(); + source = source.trim(); + + if (filename[0] === '/') filename = filename.substr(1); + else filename = path.join(path.dirname(source), filename); + + if (path.basename(filename).indexOf('.') === -1) filename += '.jade'; + filename = path.normalize(filename); + return filename; + }, + read: function (filename) { + return fs.readFileSync(path.join(originalFileDir, filename), 'utf8'); + } + }); + var actualExpectedAst = link(JSON.parse(JSON.stringify(actualInputAst))); + if (alreadyExists) { + existing = removeItem(existing, inputName); + existingExpected = removeItem(existingExpected, expectedName); + try { + var expectedInputAst = JSON.parse(fs.readFileSync(outDir + '/' + inputName, 'utf8')); + assertObjEqual(actualInputAst, expectedInputAst); + } catch (ex) { + console.log('update: ' + inputName); + fs.writeFileSync(outDir + '/' + inputName, prettyStringify(actualInputAst)); + } + try { + var expectedExpectedAst = JSON.parse(fs.readFileSync(outDir + '/' + expectedName, 'utf8')); + assertObjEqual(actualExpectedAst, expectedExpectedAst); + } catch (ex) { + console.log('update: ' + expectedName); + fs.writeFileSync(outDir + '/' + expectedName, prettyStringify(actualExpectedAst)); + } + } else { + console.log('create: ' + inputName); + fs.writeFileSync(outDir + '/' + inputName, prettyStringify(actualInputAst)); + console.log('create: ' + expectedName); + fs.writeFileSync(outDir + '/' + expectedName, prettyStringify(actualExpectedAst)); + } + } + existing.forEach(function (file) { + fs.unlinkSync(outDir + '/' + file); + }); + existingExpected.forEach(function (file) { + fs.unlinkSync(outDir + '/' + file); + }); +} + +function updateDirErrored (outDir, originalFileDir, inputFiles) { + originalFileDir = originalFileDir || outDir; + inputFiles = inputFiles || fs.readdirSync(originalFileDir).filter(function (name) { + return /\.jade$/.test(name); + }); + var existing = fs.readdirSync(outDir).filter(function (name) { + return /\.input\.json$/.test(name); + }); + inputFiles.forEach(update); + + function update (jadeName) { + var name = jadeName.replace(/\.jade$/, ''); + var inputName = name + '.input.json'; + var alreadyExists = existing.indexOf(inputName) !== -1; + var actualInputAst = load.file(jadeName, { + lex: lex, + parse: parse, + resolve: function (filename, source) { + filename = filename.trim(); + source = source.trim(); + + if (filename[0] === '/') filename = filename.substr(1); + else filename = path.join(path.dirname(source), filename); + + if (path.basename(filename).indexOf('.') === -1) filename += '.jade'; + filename = path.normalize(filename); + return filename; + }, + read: function (filename) { + return fs.readFileSync(path.join(originalFileDir, filename), 'utf8'); + } + }); + if (alreadyExists) { + existing = removeItem(existing, inputName); + try { + var expectedInputAst = JSON.parse(fs.readFileSync(outDir + '/' + inputName, 'utf8')); + assertObjEqual(actualInputAst, expectedInputAst); + } catch (ex) { + console.log('update: ' + inputName); + fs.writeFileSync(outDir + '/' + inputName, prettyStringify(actualInputAst)); + } + + var success = false; + try { + link(actualInputAst); + success = true; + } catch (ex) { + // fs.writeFileSync(outDir + '/' + expectedName, ex.message); + } + if (success) throw new Error(inputName + ' links without error'); + } else { + console.log('create: ' + inputName); + fs.writeFileSync(outDir + '/' + inputName, prettyStringify(actualInputAst)); + } + } + existing.forEach(function (file) { + fs.unlinkSync(outDir + '/' + file); + }); +} + +var upstreamCases = path.dirname(require.resolve('jade')) + '/../test/cases'; +var inputJade = fs.readdirSync(upstreamCases).filter(function (name) { + return /^(layout|include).*\.jade$/.test(name); +}); + +updateDir(__dirname + '/cases', upstreamCases, inputJade); + +updateDir(__dirname + '/special-cases', __dirname + '/special-cases-src'); + +updateDirErrored(__dirname + '/errors', __dirname + '/errors-src'); + +console.log('test cases updated');