UNPKG

dress

Version:

missing javascript prototypes(experimental)

288 lines (250 loc) 8.17 kB
describe 'Array::$set', -> it 'should change itself with the giving Array', (done) -> array = [4, 5, 2, 1, 12, 44, 18] array.$set [1, 2, 3] expect(array).to.eql [1, 2, 3] done() describe 'Array::$map', -> it 'should map correctly', (done) -> result = [4, 5, 2, 1, 12, 44, 18].$map (item) -> item + 1 expect(result).to.eql [5, 6, 3, 2, 13, 45, 19] done() describe 'Array::$$map', -> it 'should map and change itself', (done)-> result = [4, 5, 2, 1, 12, 44, 18] result.$$map (item) -> item + 1 expect(result).to.eql [5, 6, 3, 2, 13, 45, 19] done() describe 'Array::$first', -> it 'should return the first object of the array', (done) -> array = [5, 3, 6] expect(array.$first()).to.equal 5 done() describe 'Array::$last', -> it 'should return the last object of the array', (done) -> array = [7, 3, 1] expect(array.$last()).equal 1 done() describe 'Array::$find', -> it 'should find the object', (done) -> array = [1, 2, 3, 4, 5] expect(array.$find((o)-> o == 3)).to.equal 3 done() describe 'Array::$contains', -> it 'should return true if it contains the object', (done) -> array = [1, 2, 3, 4, 5] expect(array.$contains(4)).to.be.true done() it 'should return false if it does nor contain the object', (done) -> array = [1, 2, 3, 4, 5] expect(array.$contains(6)).to.be.false done() describe 'Array::$max', -> it 'should return the max number without parameter', (done) -> array = [2, 3, 1, 7, 4] expect(array.$max()).to.equal 7 done() it 'should return the max number with function parameter', (done) -> array = [ { a: 1, b: 2 }, { a: 2, c: 8}, { a: -5, c: 10} ] expect(array.$max((item) -> item.a)).to.eql { a: 2, c: 8 } done() describe 'Array::$min', -> it 'should return the min number without parameter', (done) -> array = [2, 3, 1, 7, 4] expect(array.$min()).to.equal 1 done() it 'should return the min number with function parameter', (done) -> array = [ { a: 1, b: 2 }, { a: 2, c: 8}, { a: -5, c: 10} ] expect(array.$min((item) -> item.a)).to.eql { a: -5, c: 10 } done() describe 'Array::$sort', -> it 'should sort correctly without parameter', (done) -> array = [2, 3, 1, 10, 7, 4] expect(array.$sort()).to.eql [1, 2, 3, 4, 7, 10] done() it 'should sort correctly with function parameter', (done) -> array = [ { a: 1, b: 2 }, { a: 2, c: 8}, { a: -5, c: 10} ] expect(array.$sort((item) -> item.a)).to.eql [{ a: -5, c: 10 }, { a: 1, b: 2 }, { a: 2, c: 8 }] done() it 'should sort strings correctly', (done) -> array = ['this', 'is', 'test'] expect(array.$sort()).to.eql ['is', 'test', 'this'] done() it 'should sort string correctly with function parameter', (done) -> array = [ { a: 'this' }, { a: 'is' }, { a: 'test' } ] expect(array.$sort((item) -> item.a)).to.eql [{ a: 'is' }, { a: 'test' }, { a: 'this' }] done() describe 'Array::$$sort', -> it 'should sort and change itself', (done) -> array = [4, 2, 1, 7, -4] array.$$sort() expect(array).to.eql [-4, 1, 2, 4, 7] done() describe 'Array::$samples', -> it 'should give random array if it has parameter', (done) -> array = [2, 3, 1, 10, 7, 4] result = array.$samples(2) expect(result.length).to.equal 2 for item in result expect(array.$contains(item)).to.be.true done() it 'should return different items', (done) -> array = [2, 3, 1, 10, 7, 4, 11, 9, 18] result = array.$samples(8) checked = [] for item in result expect(checked.indexOf(item)).to.equal -1 checked.push(item) done() describe 'Array::$$samples', -> it 'should change itself', (done) -> array = [2, 3, 1, 10, 7, 4] array.$$samples(2) expect(array.length).to.equal 2 for item in array expect(array.$contains(item)).to.be.true done() describe 'Array::$sample', -> it 'should give a random object', (done) -> array = [2, 3, 1, 10, 7, 4] result = array.$sample() expect(array.$contains(result)).to.be.true done() describe 'Array::$each', -> it 'should iterate correctly', (done) -> array = [1, 2, 3, 4, 5] result = [] array.$each (item) -> result.push item + 1 expect(result).to.eql [2, 3, 4, 5, 6] done() describe 'Array::$where', -> it 'should return correct objects', (done) -> array = [ { a: 1, b: 2 }, { a: 2, c: 8}, { a: -5, c: 8} ] expect(array.$where(c: 8)).to.eql [{ a: 2, c: 8 }, { a: -5, c: 8 }] expect(array.$where(a: 2, c: 8)).to.eql [{ a: 2, c: 8 }] expect(array.$where(a: 5)).to.eql [] done() describe 'Array::$$where', -> it 'should change itself', (done) -> array = [ { a: 1, b: 2 }, { a: 2, c: 8}, { a: -5, c: 8} ] array.$$where(c: 8) expect(array).to.eql [{ a: 2, c: 8 }, { a: -5, c: 8 }] done() describe 'Array::$reject', -> it 'should reject correctly', (done) -> array = [1, 2, 3, 4, 5, 6] expect(array.$reject((item) -> item % 2 == 0)).to.eql [1, 3, 5] done() describe 'Array::$$reject', -> it 'should change itself', (done) -> array = [1, 2, 3, 4, 5, 6] array.$$reject((item) -> item % 2 == 0) expect(array).to.eql [1, 3, 5] done() describe 'Array::$take', -> it 'should get first elements correctly', (done) -> array = [1, 2, 3, 4, 5, 6] expect(array.$take(3)).to.eql [1, 2, 3] done() describe 'Array::$$take', -> it 'should change itself', (done) -> array = [1, 2, 3, 4, 5, 6] array.$$take(3) expect(array).to.eql [1, 2, 3] done() describe 'Array::$drop', -> it 'should remove first elements correctly', (done) -> array = [1, 2, 3, 4, 5, 6] expect(array.$drop(3)).to.eql [4, 5, 6] done() describe 'Array::$$drop', -> it 'should change itself', (done) -> array = [1, 2, 3, 4, 5, 6] array.$$drop(3) expect(array).to.eql [4, 5, 6] done() describe 'Array::$invoke', -> it 'should run and pass parameters correctly', (done) -> array = [[1, 4, 2], [3, 2, 5]] expect(array.$invoke('$drop', 2)).to.eql [[2], [5]] done() describe 'Array::$$invoke', -> it 'should change itself', (done) -> array = [[1, 4, 2], [3, 2, 5]] array.$$invoke('$drop', 2) expect(array).to.eql [[2], [5]] done() describe 'Array::$pluck', -> it 'should return correct values', (done) -> array = [{ a: 1, b: 2 }, { a: 7, b: 6 }, { a: 9 }] expect(array.$pluck('a')).to.eql [1, 7, 9] done() describe 'Array::$$pluck', -> it 'should change itself', (done) -> array = [{ a: 1, b: 2 }, { a: 7, b: 6 }, { a: 9 }] array.$$pluck('a') expect(array).to.eql [1, 7, 9] done() describe 'Array::$group', -> it 'should return grouped object correctly', (done) -> array = [1.7, 4.3, 4.9] expect(array.$group((item) -> Math.floor(item))).to.eql { '1': [1.7], '4': [4.3, 4.9]} done() it 'should return grouped object correctly with string parameter', (done) -> array = ['this', 'is', 'test'] expect(array.$group('length')).to.eql { '2' : ['is'], '4': ['this', 'test'] } done() describe 'Array::$count', -> it 'should return the object which includes the counts', (done) -> array = [1, 2, 3, 4, 5] expect(array.$count((item) -> if item % 2 == 0 then 'even' else 'odd')).to.eql {odd: 3, even: 2} done() describe 'Array::$shuffle', -> it 'should shuffle the array', (done) -> array = [1, 2, 3, 4, 5] result = array.$shuffle() checked = [] expect(result.length).to.equal 5 for item in result expect(array.$contains(item)).to.be.true expect(checked.indexOf(item)).to.equal -1 checked.push(item) done() describe 'Array::$$shuffle', -> it 'should change itself', (done) -> array = [1, 2, 3, 4, 5] array.$$shuffle() checked = [] expect(array.length).to.equal 5 for item in array expect(array.$contains(item)).to.be.true expect(checked.indexOf(item)).to.equal -1 checked.push(item) done()