-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finishes up named blocks by adding tests and assertions for various edge cases and bugs. Related: - ember-polyfills/ember-named-blocks-polyfill#3 Fixes #1106
- Loading branch information
Chris Garrett
committed
Dec 10, 2020
1 parent
e665cb4
commit 7f8b638
Showing
9 changed files
with
222 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/@glimmer/integration-tests/test/syntax/named-blocks-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { RenderTest, jitSuite, test, preprocess, syntaxErrorFor } from '../..'; | ||
|
||
class NamedBlocksSyntaxErrors extends RenderTest { | ||
static suiteName = 'named blocks syntax errors'; | ||
|
||
@test | ||
'Defining block params on a component which has named blocks'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo as |bar|><:foo></:foo></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected block params list on <Foo> component invocation: when passing named blocks, the invocation tag cannot take block params', '<Foo as |bar|><:foo></:foo></Foo>', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'Defining named blocks on a plain element is not allowed'() { | ||
this.assert.throws(() => { | ||
preprocess('<div><:foo></:foo></div>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected named block <:foo> inside <div> HTML element', '<div><:foo></:foo></div>', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'Defining top level named blocks is not allowed'() { | ||
this.assert.throws(() => { | ||
preprocess('<:foo></:foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected named block at the top-level of a template', '<:foo></:foo>', 'test-module', 1, 0)); | ||
|
||
this.assert.throws(() => { | ||
preprocess('{{#if}}<:foo></:foo>{{/if}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected named block nested in a normal block', '<:foo></:foo>', 'test-module', 1, 7)); | ||
} | ||
|
||
@test | ||
'Passing multiple of the same named block throws an error'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo><:foo></:foo><:foo></:foo></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Component had two named blocks with the same name, `<:foo>`. Only one block with a given name may be passed', '<Foo><:foo></:foo><:foo></:foo></Foo>', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'Throws an error if there is content outside of the blocks'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo>Hello!<:foo></:foo></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected content inside <Foo> component invocation: when using named blocks, the tag cannot contain other content', '<Foo>Hello!<:foo></:foo></Foo>', 'test-module', 1, 0)); | ||
|
||
this.assert.throws(() => { | ||
preprocess('<Foo><:foo></:foo>Hello!</Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Unexpected content inside <Foo> component invocation: when using named blocks, the tag cannot contain other content', '<Foo><:foo></:foo>Hello!</Foo>', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'Cannot pass self closing named block'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo><:foo/></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('<:foo/> is not a valid named block: named blocks cannot be self-closing', '<:foo/>', 'test-module', 1, 5)); | ||
} | ||
|
||
@test | ||
'Named blocks must start with a lower case letter'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo><:Bar></:Bar></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('<:Bar> is not a valid named block, and named blocks must begin with a lowercase letter', '<:Bar></:Bar>', 'test-module', 1, 5)); | ||
|
||
this.assert.throws(() => { | ||
preprocess('<Foo><:1bar><:/1bar></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('Invalid named block named detected, you may have created a named block without a name, or you may have began your name with a number. Named blocks must have names that are at least one character long, and begin with a lower case letter', '<:/1bar>', 'test-module', 1, 12)); | ||
} | ||
|
||
@test | ||
'Named blocks cannot have arguments, attributes, or modifiers'() { | ||
this.assert.throws(() => { | ||
preprocess('<Foo><:bar attr="baz"></:bar></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('named block <:bar> cannot have attributes, arguments, or modifiers', '<:bar attr="baz"></:bar>', 'test-module', 1, 5)); | ||
|
||
this.assert.throws(() => { | ||
preprocess('<Foo><:bar @arg="baz"></:bar></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('named block <:bar> cannot have attributes, arguments, or modifiers', '<:bar @arg="baz"></:bar>', 'test-module', 1, 5)); | ||
|
||
this.assert.throws(() => { | ||
preprocess('<Foo><:bar {{modifier}}></:bar></Foo>', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('named block <:bar> cannot have attributes, arguments, or modifiers', '<:bar {{modifier}}></:bar>', 'test-module', 1, 5)); | ||
} | ||
} | ||
|
||
jitSuite(NamedBlocksSyntaxErrors); |
63 changes: 63 additions & 0 deletions
63
packages/@glimmer/integration-tests/test/syntax/yield-keywords-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { RenderTest, jitSuite, test, preprocess, syntaxErrorFor } from '../..'; | ||
|
||
class NamedBlocksSyntaxErrors extends RenderTest { | ||
static suiteName = 'yield keywords syntax errors'; | ||
|
||
@test | ||
'yield throws if receiving any named args besides `to`'() { | ||
this.assert.throws(() => { | ||
preprocess('{{yield foo="bar"}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor("yield only takes a single named argument: 'to'", 'foo="bar"', 'test-module', 1, 8)); | ||
} | ||
|
||
@test | ||
'you can only yield to a literal string value'() { | ||
this.assert.throws(() => { | ||
preprocess('{{yield to=this.bar}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('you can only yield to a literal string value', 'this.bar', 'test-module', 1, 11)); | ||
} | ||
|
||
@test | ||
'has-block throws if receiving any named args'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block foo="bar"}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block) does not take any named arguments', '{{has-block foo="bar"}}', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'has-block throws if receiving multiple positional'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block "foo" "bar"}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block) only takes a single positional argument', '{{has-block "foo" "bar"}}', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'has-block throws if receiving a value besides a string'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block this.bar}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block) can only receive a string literal as its first argument', '{{has-block this.bar}}', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'has-block-params throws if receiving any named args'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block-params foo="bar"}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block-params) does not take any named arguments', '{{has-block-params foo="bar"}}', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'has-block-params throws if receiving multiple positional'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block-params "foo" "bar"}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block-params) only takes a single positional argument', '{{has-block-params "foo" "bar"}}', 'test-module', 1, 0)); | ||
} | ||
|
||
@test | ||
'has-block-params throws if receiving a value besides a string'() { | ||
this.assert.throws(() => { | ||
preprocess('{{has-block-params this.bar}}', { meta: { moduleName: 'test-module' } }); | ||
}, syntaxErrorFor('(has-block-params) can only receive a string literal as its first argument', '{{has-block-params this.bar}}', 'test-module', 1, 0)); | ||
} | ||
} | ||
|
||
jitSuite(NamedBlocksSyntaxErrors); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters