-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {MatchPipe} from './match'; | ||
|
||
describe('MatchPipe Tests', () => { | ||
let pipe:MatchPipe; | ||
|
||
beforeEach(() => { | ||
pipe = new MatchPipe(); | ||
}); | ||
|
||
it('Should not do anything if not a string', () => { | ||
expect(pipe.transform(null, '')).toEqual(null); | ||
expect(pipe.transform(undefined, '')).toEqual(undefined); | ||
expect(pipe.transform(42, '')).toEqual(42); | ||
expect(pipe.transform({name: 'foo'}, '')).toEqual({name: 'foo'}); | ||
}); | ||
|
||
it('Should camelize properly', () => { | ||
expect(pipe.transform('foo 42', '[\\d]+$', 'g')).toEqual(['42']); | ||
expect(pipe.transform('42 foo', '[\\d]+$', 'g')).toEqual(null); | ||
expect(pipe.transform('foo', '[\\d]+$', 'g')).toEqual(null); | ||
expect(pipe.transform('FOO', '^foo')).toEqual(null); | ||
expect(pipe.transform('FOO', '^foo', 'i')).toBeTruthy(['FOO']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {PipeTransform, Pipe} from '@angular/core'; | ||
import GeneralHelper from '../helpers/helpers'; | ||
|
||
@Pipe({name: 'match'}) | ||
export class MatchPipe implements PipeTransform { | ||
|
||
transform(text: any, pattern: string, flags?: string): boolean { | ||
if (!GeneralHelper.isString(text)) { | ||
return text; | ||
} | ||
|
||
return text.match(new RegExp(pattern, flags)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {TestPipe} from './test'; | ||
|
||
describe('TestPipe Tests', () => { | ||
let pipe:TestPipe; | ||
|
||
beforeEach(() => { | ||
pipe = new TestPipe(); | ||
}); | ||
|
||
it('Should not do anything if not a string', () => { | ||
expect(pipe.transform(null, '')).toEqual(null); | ||
expect(pipe.transform(undefined, '')).toEqual(undefined); | ||
expect(pipe.transform(42, '')).toEqual(42); | ||
expect(pipe.transform({name: 'foo'}, '')).toEqual({name: 'foo'}); | ||
}); | ||
|
||
it('Should camelize properly', () => { | ||
expect(pipe.transform('foo 42', '[\\d]+$', 'g')).toBeTruthy(); | ||
expect(pipe.transform('42 foo', '[\\d]+$', 'g')).toBeFalsy(); | ||
expect(pipe.transform('foo', '[\\d]+$', 'g')).toBeFalsy(); | ||
expect(pipe.transform('FOO', '^foo')).toBeFalsy(); | ||
expect(pipe.transform('FOO', '^foo', 'i')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {PipeTransform, Pipe} from '@angular/core'; | ||
import GeneralHelper from '../helpers/helpers'; | ||
|
||
@Pipe({name: 'test'}) | ||
export class TestPipe implements PipeTransform { | ||
|
||
transform(text: any, pattern: string, flags?: string): boolean { | ||
if (!GeneralHelper.isString(text)) { | ||
return text; | ||
} | ||
|
||
return (new RegExp(pattern, flags)).test(text); | ||
} | ||
} |