From 77b600d726449cd6e6fdf788c36b2aadee96498d Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 22 Nov 2016 11:56:09 -0500 Subject: [PATCH] add {{else}} tests --- test/compiler/if-block-else/_config.js | 17 ++++++ test/compiler/if-block-else/main.html | 11 ++++ test/parser/if-block-else/input.html | 5 ++ test/parser/if-block-else/output.json | 73 ++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 test/compiler/if-block-else/_config.js create mode 100644 test/compiler/if-block-else/main.html create mode 100644 test/parser/if-block-else/input.html create mode 100644 test/parser/if-block-else/output.json diff --git a/test/compiler/if-block-else/_config.js b/test/compiler/if-block-else/_config.js new file mode 100644 index 0000000000..25c44fd65e --- /dev/null +++ b/test/compiler/if-block-else/_config.js @@ -0,0 +1,17 @@ +import * as assert from 'assert'; + +export default { + data: { + foo: true, + bar: false + }, + html: '

foo

not bar

', + test ( component, target ) { + component.set({ foo: false }); + assert.equal( target.innerHTML, '

not foo

not bar

' ); + component.set({ bar: true }); + assert.equal( target.innerHTML, '

not foo

bar

' ); + component.set({ foo: true }); + assert.equal( target.innerHTML, '

foo

bar

' ); + } +}; diff --git a/test/compiler/if-block-else/main.html b/test/compiler/if-block-else/main.html new file mode 100644 index 0000000000..5a211aa840 --- /dev/null +++ b/test/compiler/if-block-else/main.html @@ -0,0 +1,11 @@ +{{#if foo}} +

foo

+{{else}} +

not foo

+{{/if}} + +{{#if bar}} +

bar

+{{else}} +

not bar

+{{/if}} diff --git a/test/parser/if-block-else/input.html b/test/parser/if-block-else/input.html new file mode 100644 index 0000000000..cbabce939f --- /dev/null +++ b/test/parser/if-block-else/input.html @@ -0,0 +1,5 @@ +{{#if foo}} +

foo

+{{else}} +

not foo

+{{/if}} diff --git a/test/parser/if-block-else/output.json b/test/parser/if-block-else/output.json new file mode 100644 index 0000000000..8091d4c7dd --- /dev/null +++ b/test/parser/if-block-else/output.json @@ -0,0 +1,73 @@ +{ + "html": { + "start": 0, + "end": 56, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 56, + "type": "IfBlock", + "expression": { + "start": 6, + "end": 9, + "type": "Identifier", + "name": "foo" + }, + "children": [ + { + "start": 13, + "end": 23, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 16, + "end": 19, + "type": "Text", + "data": "foo" + } + ] + } + ], + "else": { + "start": 32, + "end": 49, + "type": "ElseBlock", + "children": [ + { + "start": 32, + "end": 34, + "type": "Text", + "data": "\n\t" + }, + { + "start": 34, + "end": 48, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 37, + "end": 44, + "type": "Text", + "data": "not foo" + } + ] + }, + { + "start": 48, + "end": 49, + "type": "Text", + "data": "\n" + } + ] + } + } + ] + }, + "css": null, + "js": null +}