@@ -18,7 +18,9 @@ import {
1818 HtmlAttrAst ,
1919 HtmlTextAst ,
2020 HtmlCommentAst ,
21- htmlVisitAll
21+ htmlVisitAll ,
22+ HtmlExpansionAst ,
23+ HtmlExpansionCaseAst
2224} from 'angular2/src/compiler/html_ast' ;
2325import { ParseError , ParseLocation } from 'angular2/src/compiler/parse_util' ;
2426import { humanizeDom , humanizeDomSourceSpans , humanizeLineColumn } from './html_ast_spec_utils' ;
@@ -227,7 +229,7 @@ export function main() {
227229 . toEqual ( [ [ HtmlElementAst , 'template' , 0 ] , [ HtmlAttrAst , 'k' , 'v' ] ] ) ;
228230 } ) ;
229231
230- it ( 'should support mamespace ' , ( ) => {
232+ it ( 'should support namespace ' , ( ) => {
231233 expect ( humanizeDom ( parser . parse ( '<svg:use xlink:href="Port" />' , 'TestComp' ) ) )
232234 . toEqual ( [ [ HtmlElementAst , '@svg:use' , 0 ] , [ HtmlAttrAst , '@xlink:href' , 'Port' ] ] ) ;
233235 } ) ;
@@ -240,6 +242,54 @@ export function main() {
240242 } ) ;
241243 } ) ;
242244
245+ describe ( "expansion forms" , ( ) => {
246+ it ( "should parse out expansion forms" , ( ) => {
247+ let parsed = parser . parse ( `<div>before{messages.length, plural, =0 {You have <b>no</b> messages} =1 {One {{message}}}}after</div>` ,
248+ 'TestComp' , true ) ;
249+
250+ expect ( humanizeDom ( parsed ) )
251+ . toEqual ( [
252+ [ HtmlElementAst , 'div' , 0 ] ,
253+ [ HtmlTextAst , 'before' , 1 ] ,
254+ [ HtmlExpansionAst , 'messages.length' , 'plural' ] ,
255+ [ HtmlExpansionCaseAst , '0' ] ,
256+ [ HtmlExpansionCaseAst , '1' ] ,
257+ [ HtmlTextAst , 'after' , 1 ]
258+ ] ) ;
259+
260+ let cases = ( < any > parsed . rootNodes [ 0 ] ) . children [ 1 ] . cases ;
261+
262+ expect ( humanizeDom ( new HtmlParseTreeResult ( cases [ 0 ] . expression , [ ] ) ) )
263+ . toEqual ( [
264+ [ HtmlTextAst , 'You have ' , 0 ] ,
265+ [ HtmlElementAst , 'b' , 0 ] ,
266+ [ HtmlTextAst , 'no' , 1 ] ,
267+ [ HtmlTextAst , ' messages' , 0 ] ,
268+ ] ) ;
269+
270+ expect ( humanizeDom ( new HtmlParseTreeResult ( cases [ 1 ] . expression , [ ] ) ) )
271+ . toEqual ( [ [ HtmlTextAst , 'One {{message}}' , 0 ] ] ) ;
272+ } ) ;
273+
274+ it ( "should error when expansion form is not closed" , ( ) => {
275+ let p = parser . parse ( `{messages.length, plural, =0 {one}` , 'TestComp' , true ) ;
276+ expect ( humanizeErrors ( p . errors ) )
277+ . toEqual ( [ [ null , "Invalid expansion form. Missing '}'." , '0:34' ] ] ) ;
278+ } ) ;
279+
280+ it ( "should error when expansion case is not closed" , ( ) => {
281+ let p = parser . parse ( `{messages.length, plural, =0 {one` , 'TestComp' , true ) ;
282+ expect ( humanizeErrors ( p . errors ) )
283+ . toEqual ( [ [ null , "Invalid expansion form. Missing '}'." , '0:29' ] ] ) ;
284+ } ) ;
285+
286+ it ( "should error when invalid html in the case" , ( ) => {
287+ let p = parser . parse ( `{messages.length, plural, =0 {<b/>}` , 'TestComp' , true ) ;
288+ expect ( humanizeErrors ( p . errors ) )
289+ . toEqual ( [ [ 'b' , 'Only void and foreign elements can be self closed "b"' , '0:30' ] ] ) ;
290+ } ) ;
291+ } ) ;
292+
243293 describe ( 'source spans' , ( ) => {
244294 it ( 'should store the location' , ( ) => {
245295 expect ( humanizeDomSourceSpans ( parser . parse (
0 commit comments