angular-cn/modules/@angular/common/test/pipes/replace_pipe_spec.ts

62 lines
2.2 KiB
TypeScript
Raw Normal View History

import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
import {ReplacePipe} from '@angular/common';
import {RegExpWrapper, StringJoiner} from '../../src/facade/lang';
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
export function main() {
describe('ReplacePipe', () => {
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var someNumber: number;
var str: any /** TODO #9100 */;
var pipe: any /** TODO #9100 */;
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
beforeEach(() => {
someNumber = 42;
str = 'Douglas Adams';
pipe = new ReplacePipe();
});
describe('transform', () => {
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
it('should not support input other than strings and numbers', () => {
expect(() => pipe.transform({}, 'Douglas', 'Hugh')).toThrow();
expect(() => pipe.transform([1, 2, 3], 'Douglas', 'Hugh')).toThrow();
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
});
it('should not support patterns other than strings and regular expressions', () => {
expect(() => pipe.transform(str, {}, 'Hugh')).toThrow();
expect(() => pipe.transform(str, null, 'Hugh')).toThrow();
expect(() => pipe.transform(str, 123, 'Hugh')).toThrow();
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
});
it('should not support replacements other than strings and functions', () => {
expect(() => pipe.transform(str, 'Douglas', {})).toThrow();
expect(() => pipe.transform(str, 'Douglas', null)).toThrow();
expect(() => pipe.transform(str, 'Douglas', 123)).toThrow();
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
});
it('should return a new string with the pattern replaced', () => {
var result1 = pipe.transform(str, 'Douglas', 'Hugh');
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var result2 = pipe.transform(str, RegExpWrapper.create('a'), '_');
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var result3 = pipe.transform(str, RegExpWrapper.create('a', 'i'), '_');
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var f = ((x: any /** TODO #9100 */) => { return 'Adams!'; });
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var result4 = pipe.transform(str, 'Adams', f);
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
var result5 = pipe.transform(someNumber, '2', '4');
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
expect(result1).toEqual('Hugh Adams');
expect(result2).toEqual('Dougl_s Ad_ms');
expect(result3).toEqual('Dougl_s _d_ms');
expect(result4).toEqual('Douglas Adams!');
expect(result5).toEqual('44');
feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework. feat(pipes): add ReplacePipe for string manipulation add commonly used pipe that is missing from framework.
2015-12-27 01:05:25 -05:00
});
});
});
}