Skip to content
Myr

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

1 file+18 added−35 removed

modified:test/utils.js+18 added-35 removed
4 unmodified lines
5describe('utils.etag(body)', function(){67 var str = 'Hello CRC';8 var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';9 910 it('should support strings', function(){11 utils.etag(str).should.eql('"-2034458343"');12 })13
12 unmodified lines
26 it('should support windows', function(){27 assert(utils.isAbsolute('c:\\'));28 assert(!utils.isAbsolute(':\\'));29 })30 3031 it('should unices', function(){32 assert(utils.isAbsolute('/foo/bar'));33 assert(!utils.isAbsolute('foo/bar'));34 })
18 unmodified lines
53 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 5758 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 lines
76 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 8081 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 lines
87 })8889 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 9495 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 102103 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 lines
111 it('should provide .type', function(){112 var arr = utils.parseAccept('text/html');113 arr[0].type.should.equal('text');114 })132 115116 it('should provide .subtype', function(){117 var arr = utils.parseAccept('text/html');118 arr[0].subtype.should.equal('html');119 })
5 unmodified lines
125 utils.accepts('text/html')126 .should.equal('text/html');127 })128 })146 129130 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 lines
171 it('should return the value when present', function(){172 utils.accepts('text/html', 'text/plain, text/html')173 .should.equal('text/html');174 })192 175176 it('should return undefined otherwise', function(){177 assert(null == utils.accepts('text/html', 'text/plain, application/json'));178 })179 })197 180181 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 186187 it('should return undefined otherwise', function(){188 assert(null == utils.accepts('text/html', 'image/*'));189 })190 })208 191192 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 197198 it('should return undefined otherwise', function(){199 assert(null == utils.accepts('text/html', '*/json'));200 })201 })219 202203 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 208209 it('should return undefined otherwise', function(){210 assert(null == utils.accepts('html', 'text/plain, application/json'));211 })229 212213 it('should support *', function(){214 utils.accepts('html', 'text/*')215 .should.equal('html');216
5 unmodified lines