utils.js
This file
Path
test/utils.js
79 lines · 2.2 KiB · JavaScript
Last changed by
Added req.acceptedTJ Holowaychukbefore adoptiona8fd8cb
History of this fileTake it
utils.isAbsolute() testsTj Holowaychukbefore adoption5221ecc
lines 1–16why, one step back123var utils = require('../lib/utils')4 , assert = require('assert');56describe('utils.isAbsolute()', function(){7 it('should support windows', function(){8 assert(utils.isAbsolute('c:\\'));9 assert(!utils.isAbsolute(':\\'));10 })11 12 it('should unices', function(){13 assert(utils.isAbsolute('/foo/bar'));14 assert(!utils.isAbsolute('foo/bar'));15 })16})Added utils.flatten(arr) testsTj Holowaychukbefore adoptiond56e5d6
lines 17–20why, one step back1718describe('utils.flatten(arr)', function(){19 it('should flatten an array', function(){20 var arr = ['one', ['two', ['three', 'four'], 'five']];Added utils.escape(html) testTj Holowaychukbefore adoptionce2ec94
line 21why, one step back21 utils.flatten(arr)Added utils.flatten(arr) testsTj Holowaychukbefore adoptiond56e5d6
line 22why, one step back22 .should.eql(['one', 'two', 'three', 'four', 'five']);Added utils.escape(html) testTj Holowaychukbefore adoptionce2ec94
lines 23–29why, one step back23 })24})2526describe('utils.escape(html)', function(){27 it('should escape html entities', function(){28 utils.escape('<script>foo & "bar"')29 .should.equal('<script>foo & "bar"')Added utils.flatten(arr) testsTj Holowaychukbefore adoptiond56e5d6
lines 30–31why, one step back30 })31})Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
line 32why, one step back32renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
line 33why, one step back33describe('utils.parseQuality(str)', function(){Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
line 34why, one step back34 it('should default quality to 1', function(){renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
lines 35–36why, one step back35 utils.parseQuality('text/html')36 .should.eql([{ value: 'text/html', quality: 1 }]);Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
lines 37–39why, one step back37 })38 39 it('should parse qvalues', function(){renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
lines 40–41why, one step back40 utils.parseQuality('text/html; q=0.5')41 .should.eql([{ value: 'text/html', quality: 0.5 }]);Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
line 42why, one step back42renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
lines 43–44why, one step back43 utils.parseQuality('text/html; q=.2')44 .should.eql([{ value: 'text/html', quality: 0.2 }]);Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
lines 45–47why, one step back45 })46 47 it('should work with messed up whitespace', function(){renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
lines 48–49why, one step back48 utils.parseQuality('text/html ; q = .2')49 .should.eql([{ value: 'text/html', quality: 0.2 }]);Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
lines 50–51why, one step back50 })51 more testsTJ Holowaychukbefore adoptionfd06084
lines 52–59why, one step back52 it('should work with multiples', function(){53 var str = 'da, en;q=.5, en-gb;q=.8';54 var arr = utils.parseQuality(str);55 arr[0].value.should.equal('da');56 arr[1].value.should.equal('en-gb');57 arr[2].value.should.equal('en');58 })59 Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
lines 60–61why, one step back60 it('should sort by quality', function(){61 var str = 'text/plain;q=.2, application/json, text/html;q=0.5';renamed prev util to parseQuality()TJ Holowaychukbefore adoption29d4ffd
lines 62–65why, one step back62 var arr = utils.parseQuality(str);63 arr[0].value.should.equal('application/json');64 arr[1].value.should.equal('text/html');65 arr[2].value.should.equal('text/plain');Added utils.parseAccepts(str)TJ Holowaychukbefore adoptionfe5efa5
lines 66–67why, one step back66 })67})Added parseAccepts() utilTJ Holowaychukbefore adoption2855004
line 68why, one step back68Added req.acceptedTJ Holowaychukbefore adoptiona8fd8cb
line 69why, one step back69describe('utils.parseAccept(str)', function(){Added parseAccepts() utilTJ Holowaychukbefore adoption2855004
line 70why, one step back70 it('should provide .type', function(){Added req.acceptedTJ Holowaychukbefore adoptiona8fd8cb
line 71why, one step back71 var arr = utils.parseAccept('text/html');Added parseAccepts() utilTJ Holowaychukbefore adoption2855004
lines 72–75why, one step back72 arr[0].type.should.equal('text');73 })74 75 it('should provide .subtype', function(){Added req.acceptedTJ Holowaychukbefore adoptiona8fd8cb
line 76why, one step back76 var arr = utils.parseAccept('text/html');Added parseAccepts() utilTJ Holowaychukbefore adoption2855004
lines 77–79why, one step back77 arr[0].subtype.should.equal('html');78 })79})