1+ import { ddescribe , describe , it , iit , xit , expect , beforeEach , afterEach } from 'angular2/test_lib' ;
2+
3+ import { SlicePipe } from 'angular2/pipes' ;
4+
5+ export function main ( ) {
6+ describe ( "SlicePipe" , ( ) => {
7+ var list ;
8+ var str ;
9+ var pipe ;
10+
11+ beforeEach ( ( ) => {
12+ list = [ 1 , 2 , 3 , 4 , 5 ] ;
13+ str = 'tuvwxyz' ;
14+ pipe = new SlicePipe ( ) ;
15+ } ) ;
16+
17+ describe ( "supports" , ( ) => {
18+ it ( "should support strings" , ( ) => { expect ( pipe . supports ( str ) ) . toBe ( true ) ; } ) ;
19+ it ( "should support lists" , ( ) => { expect ( pipe . supports ( list ) ) . toBe ( true ) ; } ) ;
20+
21+ it ( "should not support other objects" , ( ) => {
22+ expect ( pipe . supports ( new Object ( ) ) ) . toBe ( false ) ;
23+ expect ( pipe . supports ( null ) ) . toBe ( false ) ;
24+ } ) ;
25+ } ) ;
26+
27+ describe ( "transform" , ( ) => {
28+
29+ it ( 'should return all items after START index when START is positive and END is omitted' ,
30+ ( ) => {
31+ expect ( pipe . transform ( list , [ 3 ] ) ) . toEqual ( [ 4 , 5 ] ) ;
32+ expect ( pipe . transform ( str , [ 3 ] ) ) . toEqual ( 'wxyz' ) ;
33+ } ) ;
34+
35+ it ( 'should return last START items when START is negative and END is omitted' , ( ) => {
36+ expect ( pipe . transform ( list , [ - 3 ] ) ) . toEqual ( [ 3 , 4 , 5 ] ) ;
37+ expect ( pipe . transform ( str , [ - 3 ] ) ) . toEqual ( 'xyz' ) ;
38+ } ) ;
39+
40+ it ( 'should return all items between START and END index when START and END are positive' ,
41+ ( ) => {
42+ expect ( pipe . transform ( list , [ 1 , 3 ] ) ) . toEqual ( [ 2 , 3 ] ) ;
43+ expect ( pipe . transform ( str , [ 1 , 3 ] ) ) . toEqual ( 'uv' ) ;
44+ } ) ;
45+
46+ it ( 'should return all items between START and END from the end when START and END are negative' ,
47+ ( ) => {
48+ expect ( pipe . transform ( list , [ - 4 , - 2 ] ) ) . toEqual ( [ 2 , 3 ] ) ;
49+ expect ( pipe . transform ( str , [ - 4 , - 2 ] ) ) . toEqual ( 'wx' ) ;
50+ } ) ;
51+
52+ it ( 'should return an empty value if START is greater than END' , ( ) => {
53+ expect ( pipe . transform ( list , [ 4 , 2 ] ) ) . toEqual ( [ ] ) ;
54+ expect ( pipe . transform ( str , [ 4 , 2 ] ) ) . toEqual ( '' ) ;
55+ } ) ;
56+
57+ it ( 'should return an empty value if START greater than input length' , ( ) => {
58+ expect ( pipe . transform ( list , [ 99 ] ) ) . toEqual ( [ ] ) ;
59+ expect ( pipe . transform ( str , [ 99 ] ) ) . toEqual ( '' ) ;
60+ } ) ;
61+
62+ it ( 'should return entire input if START is negative and greater than input length' , ( ) => {
63+ expect ( pipe . transform ( list , [ - 99 ] ) ) . toEqual ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
64+ expect ( pipe . transform ( str , [ - 99 ] ) ) . toEqual ( 'tuvwxyz' ) ;
65+ } ) ;
66+
67+ it ( 'should not modify the input list' , ( ) => {
68+ expect ( pipe . transform ( list , [ 2 ] ) ) . toEqual ( [ 3 , 4 , 5 ] ) ;
69+ expect ( list ) . toEqual ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
70+ } ) ;
71+
72+ } ) ;
73+
74+ } ) ;
75+ }
0 commit comments