OLD | NEW |
(Empty) | |
| 1 library limit_to_spec; |
| 2 |
| 3 import '../_specs.dart'; |
| 4 |
| 5 main() { |
| 6 describe('orderBy formatter', () { |
| 7 beforeEach((Scope scope, Parser parse, FormatterMap formatters) { |
| 8 scope.context['list'] = 'abcdefgh'.split(''); |
| 9 scope.context['string'] = 'tuvwxyz'; |
| 10 }); |
| 11 |
| 12 it('should return the first X items when X is positive', (Scope scope, Parse
r parse, FormatterMap formatters) { |
| 13 scope.context['limit'] = 3; |
| 14 expect(parse('list | limitTo: 3').eval(scope.context, formatters)).toEqual
(['a', 'b', 'c']); |
| 15 expect(parse('list | limitTo: limit').eval(scope.context, formatters)).toE
qual(['a', 'b', 'c']); |
| 16 expect(parse('string | limitTo: 3').eval(scope.context, formatters)).toEqu
al('tuv'); |
| 17 expect(parse('string | limitTo: limit').eval(scope.context, formatters)).t
oEqual('tuv'); |
| 18 }); |
| 19 |
| 20 it('should return the last X items when X is negative', (Scope scope, Parser
parse, FormatterMap formatters) { |
| 21 scope.context['limit'] = 3; |
| 22 expect(parse('list | limitTo: -3').eval(scope.context, formatters)).toEqua
l(['f', 'g', 'h']); |
| 23 expect(parse('list | limitTo: -limit').eval(scope.context, formatters)).to
Equal(['f', 'g', 'h']); |
| 24 expect(parse('string | limitTo: -3').eval(scope.context, formatters)).toEq
ual('xyz'); |
| 25 expect(parse('string | limitTo: -limit').eval(scope.context, formatters)).
toEqual('xyz'); |
| 26 }); |
| 27 |
| 28 it('should return an null when limiting null list', |
| 29 (Scope scope, Parser parse, FormatterMap formatters) { |
| 30 expect(parse('null | limitTo: 1').eval(scope.context, formatters)).toEqual
(null); |
| 31 expect(parse('thisIsNull | limitTo: 1').eval(scope.context, formatters)).t
oEqual(null); |
| 32 }); |
| 33 |
| 34 it('should return an empty array when X cannot be parsed', |
| 35 (Scope scope, Parser parse, FormatterMap formatters) { |
| 36 expect(parse('list | limitTo: bogus').eval(scope.context, formatters)).toE
qual([]); |
| 37 expect(parse('string | limitTo: null').eval(scope.context, formatters)).to
Equal([]); |
| 38 expect(parse('string | limitTo: thisIsNull').eval(scope.context, formatter
s)).toEqual([]); |
| 39 }); |
| 40 |
| 41 it('should return a copy of input array if X is exceeds array length', |
| 42 (Scope scope, Parser parse, FormatterMap formatters) { |
| 43 expect(parse('list | limitTo: 20').eval(scope.context, formatters)).toEqua
l(scope.context['list']); |
| 44 expect(parse('list | limitTo: -20').eval(scope.context, formatters)).toEqu
al(scope.context['list']); |
| 45 expect(parse('list | limitTo: 20').eval(scope.context, formatters)).not.to
Be(scope.context['list']); |
| 46 }); |
| 47 |
| 48 it('should return the entire string if X exceeds input length', |
| 49 (Scope scope, Parser parse, FormatterMap formatters) { |
| 50 expect(parse('string | limitTo: 20').eval(scope.context, formatters)).toEq
ual(scope.context['string']); |
| 51 expect(parse('string | limitTo: -20').eval(scope.context, formatters)).toE
qual(scope.context['string']); |
| 52 }); |
| 53 |
| 54 }); |
| 55 } |
OLD | NEW |