2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2018-05-09 16:49:39 -07:00
|
|
|
import {assertDefined, assertEqual} from './assert';
|
2018-09-05 16:15:37 -07:00
|
|
|
import {LNode, TNode, TNodeType} from './interfaces/node';
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-09-05 16:15:37 -07:00
|
|
|
export function assertNodeType(tNode: TNode, type: TNodeType) {
|
|
|
|
assertDefined(tNode, 'should be called with a TNode');
|
|
|
|
assertEqual(tNode.type, type, `should be a ${typeName(type)}`);
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
2018-09-05 16:15:37 -07:00
|
|
|
export function assertNodeOfPossibleTypes(tNode: TNode, ...types: TNodeType[]) {
|
|
|
|
assertDefined(tNode, 'should be called with a TNode');
|
|
|
|
const found = types.some(type => tNode.type === type);
|
2018-08-22 17:18:03 +02:00
|
|
|
assertEqual(
|
|
|
|
found, true,
|
2018-09-05 16:15:37 -07:00
|
|
|
`Should be one of ${types.map(typeName).join(', ')} but got ${typeName(tNode.type)}`);
|
2017-12-18 15:14:09 +01:00
|
|
|
}
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-05-17 12:54:57 -07:00
|
|
|
function typeName(type: TNodeType): string {
|
|
|
|
if (type == TNodeType.Projection) return 'Projection';
|
|
|
|
if (type == TNodeType.Container) return 'Container';
|
|
|
|
if (type == TNodeType.View) return 'View';
|
|
|
|
if (type == TNodeType.Element) return 'Element';
|
2018-08-22 17:18:03 +02:00
|
|
|
if (type == TNodeType.ElementContainer) return 'ElementContainer';
|
2018-02-12 22:46:15 -08:00
|
|
|
return '<unknown>';
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|