fix long list params test
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 5ba6c30 · Browse files · 1 file·+18 added−35 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+18 added−35 removed
- tests:+18 added−35 removed
Provenance
- Commit
99bc628- Tree
c5af882- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
5ba6c30
1 file changed+18 added−35 removed
modified:test/utils.js+18 added-35 removed
4 unmodified lines5 describe('utils.etag(body)', function(){6 7 var str = 'Hello CRC';8 var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';9- 9+10 it('should support strings', function(){11 utils.etag(str).should.eql('"-2034458343"');12 })13 12 unmodified lines26 it('should support windows', function(){27 assert(utils.isAbsolute('c:\\'));28 assert(!utils.isAbsolute(':\\'));29 })30- 30+31 it('should unices', function(){32 assert(utils.isAbsolute('/foo/bar'));33 assert(!utils.isAbsolute('foo/bar'));34 })18 unmodified lines53 it('should default quality to 1', function(){54 utils.parseParams('text/html')55 .should.eql([{ value: 'text/html', quality: 1, params: {}, originalIndex: 0 }]);56 })57- 57+58 it('should parse qvalues', function(){59 utils.parseParams('text/html; q=0.5')60 .should.eql([{ value: 'text/html', quality: 0.5, params: {}, originalIndex: 0 }]);61 14 unmodified lines76 it('should work with messed up whitespace', function(){77 utils.parseParams('text/html ; q = .2')78 .should.eql([{ value: 'text/html', quality: 0.2, params: {}, originalIndex: 0 }]);79 })80- 80+81 it('should work with multiples', function(){82 var str = 'da, en;q=.5, en-gb;q=.8';83 var arr = utils.parseParams(str);84 arr[0].value.should.equal('da');2 unmodified lines87 })88 89 it('should work with long lists', function(){90 var str = 'en, nl, fr, de, ja, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl';91- var arr = utils.parseParams(str);92- arr[0].value.should.equal('en');93- arr[1].value.should.equal('nl');94- arr[2].value.should.equal('fr');95- arr[4].value.should.equal('de');96- arr[5].value.should.equal('ja');97- arr[6].value.should.equal('it');98- arr[7].value.should.equal('es');99- arr[8].value.should.equal('pt');100- arr[9].value.should.equal('pt-PT');101- arr[10].value.should.equal('da');102- arr[11].value.should.equal('fi');103- arr[12].value.should.equal('nb');104- arr[13].value.should.equal('sv');105- arr[14].value.should.equal('ko');106- arr[15].value.should.equal('zh-Hans');107- arr[16].value.should.equal('zh-Hant');108- arr[17].value.should.equal('ru');109- arr[18].value.should.equal('pl');91+ var arr = utils.parseParams(str).map(function(o){ return o.value });92+ arr.should.eql(str.split(', '));93 })111- 94+95 it('should sort by quality', function(){96 var str = 'text/plain;q=.2, application/json, text/html;q=0.5';97 var arr = utils.parseParams(str);98 arr[0].value.should.equal('application/json');99 arr[1].value.should.equal('text/html');100 arr[2].value.should.equal('text/plain');101 })119- 102+103 it('should exclude those with a quality of 0', function(){104 var str = 'text/plain;q=.2, application/json, text/html;q=0';105 var arr = utils.parseParams(str);106 arr.should.have.length(2);4 unmodified lines111 it('should provide .type', function(){112 var arr = utils.parseAccept('text/html');113 arr[0].type.should.equal('text');114 })132- 115+116 it('should provide .subtype', function(){117 var arr = utils.parseAccept('text/html');118 arr[0].subtype.should.equal('html');119 })5 unmodified lines125 utils.accepts('text/html')126 .should.equal('text/html');127 })128 })146- 129+130 describe('when a string is empty', function(){131 it('should return the value', function(){132 utils.accepts('text/html', '')133 .should.equal('text/html');37 unmodified lines171 it('should return the value when present', function(){172 utils.accepts('text/html', 'text/plain, text/html')173 .should.equal('text/html');174 })192- 175+176 it('should return undefined otherwise', function(){177 assert(null == utils.accepts('text/html', 'text/plain, application/json'));178 })179 })197- 180+181 describe('when accepting */subtype', function(){182 it('should return the value when present', function(){183 utils.accepts('text/html', 'text/*')184 .should.equal('text/html');185 })203- 186+187 it('should return undefined otherwise', function(){188 assert(null == utils.accepts('text/html', 'image/*'));189 })190 })208- 191+192 describe('when accepting type/*', function(){193 it('should return the value when present', function(){194 utils.accepts('text/html', '*/html')195 .should.equal('text/html');196 })214- 197+198 it('should return undefined otherwise', function(){199 assert(null == utils.accepts('text/html', '*/json'));200 })201 })219- 202+203 describe('when an extension is given', function(){204 it('should return the value when present', function(){205 utils.accepts('html', 'text/html, application/json')206 .should.equal('html');207 })225- 208+209 it('should return undefined otherwise', function(){210 assert(null == utils.accepts('html', 'text/plain, application/json'));211 })229- 212+213 it('should support *', function(){214 utils.accepts('html', 'text/*')215 .should.equal('html');216 5 unmodified lines