-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathrename_spec.ts
61 lines (52 loc) · 1.92 KB
/
rename_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @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:no-non-null-assertion
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);
});
});