|
| 1 | +import {describe, it, expect, beforeEach, ddescribe, iit, xit} from 'angular2/test_lib'; |
| 2 | + |
| 3 | +import {List, ListWrapper, StringMap, StringMapWrapper} from 'angular2/src/facade/collection'; |
| 4 | + |
| 5 | +export function main() { |
| 6 | + describe('ListWrapper', () => { |
| 7 | + var l: List<int>; |
| 8 | + |
| 9 | + describe('splice', () => { |
| 10 | + it('should remove sublist of given length and return it', () => { |
| 11 | + var list = [1, 2, 3, 4, 5, 6]; |
| 12 | + expect(ListWrapper.splice(list, 1, 3)).toEqual([2, 3, 4]); |
| 13 | + expect(list).toEqual([1, 5, 6]); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should support negative start', () => { |
| 17 | + var list = [1, 2, 3, 4, 5, 6]; |
| 18 | + expect(ListWrapper.splice(list, -5, 3)).toEqual([2, 3, 4]); |
| 19 | + expect(list).toEqual([1, 5, 6]); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('fill', () => { |
| 24 | + beforeEach(() => { l = [1, 2, 3, 4]; }); |
| 25 | + |
| 26 | + it('should fill the whole list if neither start nor end are specified', () => { |
| 27 | + ListWrapper.fill(l, 9); |
| 28 | + expect(l).toEqual([9, 9, 9, 9]); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should fill up to the end if end is not specified', () => { |
| 32 | + ListWrapper.fill(l, 9, 1); |
| 33 | + expect(l).toEqual([1, 9, 9, 9]); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should support negative start', () => { |
| 37 | + ListWrapper.fill(l, 9, -1); |
| 38 | + expect(l).toEqual([1, 2, 3, 9]); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should support negative end', () => { |
| 42 | + ListWrapper.fill(l, 9, -2, -1); |
| 43 | + expect(l).toEqual([1, 2, 9, 4]); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('slice', () => { |
| 48 | + beforeEach(() => { l = [1, 2, 3, 4]; }); |
| 49 | + |
| 50 | + it('should return the whole list if neither start nor end are specified', |
| 51 | + () => { expect(ListWrapper.slice(l)).toEqual([1, 2, 3, 4]); }); |
| 52 | + |
| 53 | + it('should return up to the end if end is not specified', |
| 54 | + () => { expect(ListWrapper.slice(l, 1)).toEqual([2, 3, 4]); }); |
| 55 | + |
| 56 | + it('should support negative start', () => { expect(ListWrapper.slice(l, -1)).toEqual([4]); }); |
| 57 | + |
| 58 | + it('should support negative end', |
| 59 | + () => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('StringMapWrapper', () => { |
| 64 | + describe('equals', () => { |
| 65 | + it('should return true when comparing empty maps', |
| 66 | + () => { expect(StringMapWrapper.equals({}, {})).toBe(true); }); |
| 67 | + |
| 68 | + it('should return true when comparing the same map', () => { |
| 69 | + var m1 = {'a': 1, 'b': 2, 'c': 3}; |
| 70 | + expect(StringMapWrapper.equals(m1, m1)).toBe(true); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should return true when comparing different maps with the same keys and values', () => { |
| 74 | + var m1 = {'a': 1, 'b': 2, 'c': 3}; |
| 75 | + var m2 = {'a': 1, 'b': 2, 'c': 3}; |
| 76 | + expect(StringMapWrapper.equals(m1, m2)).toBe(true); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should return false when comparing maps with different numbers of keys', () => { |
| 80 | + var m1 = {'a': 1, 'b': 2, 'c': 3}; |
| 81 | + var m2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4}; |
| 82 | + expect(StringMapWrapper.equals(m1, m2)).toBe(false); |
| 83 | + expect(StringMapWrapper.equals(m2, m1)).toBe(false); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should return false when comparing maps with different keys', () => { |
| 87 | + var m1 = {'a': 1, 'b': 2, 'c': 3}; |
| 88 | + var m2 = {'a': 1, 'b': 2, 'CC': 3}; |
| 89 | + expect(StringMapWrapper.equals(m1, m2)).toBe(false); |
| 90 | + expect(StringMapWrapper.equals(m2, m1)).toBe(false); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should return false when comparing maps with different values', () => { |
| 94 | + var m1 = {'a': 1, 'b': 2, 'c': 3}; |
| 95 | + var m2 = {'a': 1, 'b': 20, 'c': 3}; |
| 96 | + expect(StringMapWrapper.equals(m1, m2)).toBe(false); |
| 97 | + expect(StringMapWrapper.equals(m2, m1)).toBe(false); |
| 98 | + }); |
| 99 | + }); |
| 100 | + }); |
| 101 | +} |
0 commit comments