2016-12-08 19:33:24 -05:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-12-08 19:33:24 -05:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {LowerCasePipe, TitleCasePipe, UpperCasePipe} from '@angular/common';
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-12-08 19:33:24 -05:00
|
|
|
describe('LowerCasePipe', () => {
|
|
|
|
let pipe: LowerCasePipe;
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
pipe = new LowerCasePipe();
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should return lowercase', () => {
|
|
|
|
expect(pipe.transform('FOO')).toEqual('foo');
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
|
|
|
it('should lowercase when there is a new value', () => {
|
|
|
|
expect(pipe.transform('FOO')).toEqual('foo');
|
|
|
|
expect(pipe.transform('BAr')).toEqual('bar');
|
|
|
|
});
|
|
|
|
|
2020-03-27 06:22:08 -04:00
|
|
|
it('should map null to null', () => {
|
|
|
|
expect(pipe.transform(null)).toEqual(null);
|
|
|
|
});
|
|
|
|
it('should map undefined to null', () => {
|
|
|
|
expect(pipe.transform(undefined)).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not support numbers', () => {
|
|
|
|
expect(() => pipe.transform(0 as any)).toThrowError();
|
|
|
|
});
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should not support other objects', () => {
|
2020-03-27 06:22:08 -04:00
|
|
|
expect(() => pipe.transform({} as any)).toThrowError();
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('TitleCasePipe', () => {
|
|
|
|
let pipe: TitleCasePipe;
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
pipe = new TitleCasePipe();
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should return titlecase', () => {
|
|
|
|
expect(pipe.transform('foo')).toEqual('Foo');
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should return titlecase for subsequent words', () => {
|
|
|
|
expect(pipe.transform('one TWO Three fouR')).toEqual('One Two Three Four');
|
|
|
|
});
|
2016-12-16 18:24:26 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should support empty strings', () => {
|
|
|
|
expect(pipe.transform('')).toEqual('');
|
|
|
|
});
|
2016-12-16 18:24:26 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should persist whitespace', () => {
|
|
|
|
expect(pipe.transform('one two')).toEqual('One Two');
|
|
|
|
});
|
2016-12-16 18:24:26 -05:00
|
|
|
|
2016-12-08 19:33:24 -05:00
|
|
|
it('should titlecase when there is a new value', () => {
|
|
|
|
expect(pipe.transform('bar')).toEqual('Bar');
|
|
|
|
expect(pipe.transform('foo')).toEqual('Foo');
|
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should not capitalize letter after the quotes', () => {
|
|
|
|
expect(pipe.transform('it\'s complicated')).toEqual('It\'s Complicated');
|
|
|
|
});
|
2018-03-13 22:46:10 -04:00
|
|
|
|
|
|
|
it('should not treat non-space character as a separator', () => {
|
|
|
|
expect(pipe.transform('one,two,three')).toEqual('One,two,three');
|
|
|
|
expect(pipe.transform('true|false')).toEqual('True|false');
|
|
|
|
expect(pipe.transform('foo-vs-bar')).toEqual('Foo-vs-bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support support all whitespace characters', () => {
|
|
|
|
expect(pipe.transform('one\ttwo')).toEqual('One\tTwo');
|
|
|
|
expect(pipe.transform('three\rfour')).toEqual('Three\rFour');
|
|
|
|
expect(pipe.transform('five\nsix')).toEqual('Five\nSix');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work properly for non-latin alphabet', () => {
|
|
|
|
expect(pipe.transform('føderation')).toEqual('Føderation');
|
|
|
|
expect(pipe.transform('poniedziałek')).toEqual('Poniedziałek');
|
|
|
|
expect(pipe.transform('éric')).toEqual('Éric');
|
|
|
|
});
|
|
|
|
|
2020-03-27 06:22:08 -04:00
|
|
|
it('should map null to null', () => {
|
|
|
|
expect(pipe.transform(null)).toEqual(null);
|
|
|
|
});
|
|
|
|
it('should map undefined to null', () => {
|
|
|
|
expect(pipe.transform(undefined)).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not support numbers', () => {
|
|
|
|
expect(() => pipe.transform(0 as any)).toThrowError();
|
|
|
|
});
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should not support other objects', () => {
|
2020-03-27 06:22:08 -04:00
|
|
|
expect(() => pipe.transform({} as any)).toThrowError();
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('UpperCasePipe', () => {
|
|
|
|
let pipe: UpperCasePipe;
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
pipe = new UpperCasePipe();
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should return uppercase', () => {
|
|
|
|
expect(pipe.transform('foo')).toEqual('FOO');
|
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
|
|
|
|
it('should uppercase when there is a new value', () => {
|
|
|
|
expect(pipe.transform('foo')).toEqual('FOO');
|
|
|
|
expect(pipe.transform('bar')).toEqual('BAR');
|
|
|
|
});
|
|
|
|
|
2020-03-27 06:22:08 -04:00
|
|
|
it('should map null to null', () => {
|
|
|
|
expect(pipe.transform(null)).toEqual(null);
|
|
|
|
});
|
|
|
|
it('should map undefined to null', () => {
|
|
|
|
expect(pipe.transform(undefined)).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not support numbers', () => {
|
|
|
|
expect(() => pipe.transform(0 as any)).toThrowError();
|
|
|
|
});
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should not support other objects', () => {
|
2020-03-27 06:22:08 -04:00
|
|
|
expect(() => pipe.transform({} as any)).toThrowError();
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
2016-12-08 19:33:24 -05:00
|
|
|
});
|
|
|
|
}
|