mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
New rules to deal with templates using a .template extension. Apply the template only to those files, then remove the .template suffix. Also added a new rename() rule that takes a matcher and a renamer. Nothing big there. Also added a new composeFileOperator() that compose operators one after the other.
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
/**
|
|
* @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
|
|
*/
|
|
// tslint:disable:non-null-operator
|
|
import { of as observableOf } from 'rxjs';
|
|
import { SchematicContext } from '../engine/interface';
|
|
import { HostTree } from '../tree/host-tree';
|
|
import { callRule } from './call';
|
|
import { rename } from './rename';
|
|
|
|
|
|
const context: SchematicContext = null !;
|
|
|
|
|
|
describe('rename', () => {
|
|
it('works', done => {
|
|
const tree = new HostTree();
|
|
tree.create('a/b/file1', 'hello world');
|
|
tree.create('a/b/file2', 'hello world');
|
|
tree.create('a/c/file3', 'hello world');
|
|
|
|
let i = 0;
|
|
|
|
// Rename all files that contain 'b' to 'hello'.
|
|
callRule(rename(x => !!x.match(/b/), () => 'hello' + (i++)), observableOf(tree), context)
|
|
.toPromise()
|
|
.then(result => {
|
|
expect(result.exists('a/b/file1')).toBe(false);
|
|
expect(result.exists('a/b/file2')).toBe(false);
|
|
expect(result.exists('hello0')).toBe(true);
|
|
expect(result.exists('hello1')).toBe(true);
|
|
expect(result.exists('a/c/file3')).toBe(true);
|
|
})
|
|
.then(done, done.fail);
|
|
});
|
|
|
|
it('works (2)', done => {
|
|
const tree = new HostTree();
|
|
tree.create('a/b/file1', 'hello world');
|
|
tree.create('a/b/file2', 'hello world');
|
|
tree.create('a/c/file3', 'hello world');
|
|
|
|
let i = 0;
|
|
|
|
// Rename all files that contain 'b' to 'hello'.
|
|
callRule(rename(x => !!x.match(/b/), x => x + (i++)), observableOf(tree), context)
|
|
.toPromise()
|
|
.then(result => {
|
|
expect(result.exists('a/b/file1')).toBe(false);
|
|
expect(result.exists('a/b/file2')).toBe(false);
|
|
expect(result.exists('a/b/file10')).toBe(true);
|
|
expect(result.exists('a/b/file21')).toBe(true);
|
|
expect(result.exists('a/c/file3')).toBe(true);
|
|
})
|
|
.then(done, done.fail);
|
|
});
|
|
});
|