|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +// tslint:disable:non-null-operator |
| 9 | +import { of as observableOf } from 'rxjs'; |
| 10 | +import { SchematicContext } from '../engine/interface'; |
| 11 | +import { HostTree } from '../tree/host-tree'; |
| 12 | +import { callRule } from './call'; |
| 13 | +import { rename } from './rename'; |
| 14 | + |
| 15 | + |
| 16 | +const context: SchematicContext = null !; |
| 17 | + |
| 18 | + |
| 19 | +describe('rename', () => { |
| 20 | + it('works', done => { |
| 21 | + const tree = new HostTree(); |
| 22 | + tree.create('a/b/file1', 'hello world'); |
| 23 | + tree.create('a/b/file2', 'hello world'); |
| 24 | + tree.create('a/c/file3', 'hello world'); |
| 25 | + |
| 26 | + let i = 0; |
| 27 | + |
| 28 | + // Rename all files that contain 'b' to 'hello'. |
| 29 | + callRule(rename(x => !!x.match(/b/), () => 'hello' + (i++)), observableOf(tree), context) |
| 30 | + .toPromise() |
| 31 | + .then(result => { |
| 32 | + expect(result.exists('a/b/file1')).toBe(false); |
| 33 | + expect(result.exists('a/b/file2')).toBe(false); |
| 34 | + expect(result.exists('hello0')).toBe(true); |
| 35 | + expect(result.exists('hello1')).toBe(true); |
| 36 | + expect(result.exists('a/c/file3')).toBe(true); |
| 37 | + }) |
| 38 | + .then(done, done.fail); |
| 39 | + }); |
| 40 | + |
| 41 | + it('works (2)', done => { |
| 42 | + const tree = new HostTree(); |
| 43 | + tree.create('a/b/file1', 'hello world'); |
| 44 | + tree.create('a/b/file2', 'hello world'); |
| 45 | + tree.create('a/c/file3', 'hello world'); |
| 46 | + |
| 47 | + let i = 0; |
| 48 | + |
| 49 | + // Rename all files that contain 'b' to 'hello'. |
| 50 | + callRule(rename(x => !!x.match(/b/), x => x + (i++)), observableOf(tree), context) |
| 51 | + .toPromise() |
| 52 | + .then(result => { |
| 53 | + expect(result.exists('a/b/file1')).toBe(false); |
| 54 | + expect(result.exists('a/b/file2')).toBe(false); |
| 55 | + expect(result.exists('a/b/file10')).toBe(true); |
| 56 | + expect(result.exists('a/b/file21')).toBe(true); |
| 57 | + expect(result.exists('a/c/file3')).toBe(true); |
| 58 | + }) |
| 59 | + .then(done, done.fail); |
| 60 | + }); |
| 61 | +}); |
0 commit comments