This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added parser for
limitTo
Angular filter
- Loading branch information
Showing
4 changed files
with
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import parseNgIterator from '../../src/parser/parse-ng-iterator'; | ||
|
||
describe('Parser', () => { | ||
describe('parseNgIterator()', () => { | ||
it('should throw an error for invalid expression', () => { | ||
let error: Error; | ||
|
||
try { | ||
parseNgIterator('Test expression'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toEqual(new Error('Invalid iterator expression \'Test expression\'')); | ||
}); | ||
|
||
it('should throw an error for invalid left-side expression of the iterator', () => { | ||
let error: Error; | ||
|
||
try { | ||
parseNgIterator('() in numbers'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toEqual(new Error('Invalid left-side expression () in iterator \'() in numbers\'')); | ||
}); | ||
|
||
it('should throw an error for invalid alias in the iterator', () => { | ||
let error: Error; | ||
|
||
try { | ||
parseNgIterator('number in numbers as this'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toEqual(new Error( | ||
'Iterator alias this is invalid - must be a valid JS identifier which is not a reserved name' | ||
)); | ||
}); | ||
|
||
it('should convert limitTo filter', () => { | ||
expect(parseNgIterator('number in numbers | limitTo:numLimit')).toEqual({ | ||
aliasAs: undefined, | ||
collectionIdentifier: 'numbers', | ||
collectionTransform: ['.slice(0, 0 + numLimit)'], | ||
keyIdentifier: undefined, | ||
valueIdentifier: 'number' | ||
}); | ||
|
||
expect(parseNgIterator('number in numbers | limitTo : numLimit : limitBegin')).toEqual({ | ||
aliasAs: undefined, | ||
collectionIdentifier: 'numbers', | ||
collectionTransform: ['.slice(limitBegin, limitBegin + numLimit)'], | ||
keyIdentifier: undefined, | ||
valueIdentifier: 'number' | ||
}); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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