utils.js
This file
Path
test/utils.js
95 lines · 2.7 KiB · JavaScript
Last changed by
Use safe-buffer for improved Buffer APIDouglas Christopher Wilsonbefore adoption12c3712
History of this fileTake it
The walk stopped after 200 commits: lines older than dc48f27 point at it.
deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 1–2why, one step back12var assert = require('assert');Use safe-buffer for improved Buffer APIDouglas Christopher Wilsonbefore adoption12c3712
line 3why, one step back3var Buffer = require('safe-buffer').Bufferdeps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 4–8why, one step back4var utils = require('../lib/utils');56describe('utils.etag(body, encoding)', function(){7 it('should support strings', function(){8 utils.etag('express!')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 9why, one step back9 .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 10–13why, one step back10 })1112 it('should support utf8 strings', function(){13 utils.etag('express❤', 'utf8')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 14why, one step back14 .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 15–17why, one step back15 })1617 it('should support buffer', function(){Use safe-buffer for improved Buffer APIDouglas Christopher Wilsonbefore adoption12c3712
line 18why, one step back18 utils.etag(Buffer.from('express!'))deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 19why, one step back19 .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 20–23why, one step back20 })2122 it('should support empty string', function(){23 utils.etag('')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 24why, one step back24 .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 25–52why, one step back25 })26})2728describe('utils.setCharset(type, charset)', function () {29 it('should do anything without type', function () {30 assert.strictEqual(utils.setCharset(), undefined);31 });3233 it('should return type if not given charset', function () {34 assert.strictEqual(utils.setCharset('text/html'), 'text/html');35 });3637 it('should keep charset if not given charset', function () {38 assert.strictEqual(utils.setCharset('text/html; charset=utf-8'), 'text/html; charset=utf-8');39 });4041 it('should set charset', function () {42 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');43 });4445 it('should override charset', function () {46 assert.strictEqual(utils.setCharset('text/html; charset=iso-8859-1', 'utf-8'), 'text/html; charset=utf-8');47 });48});4950describe('utils.wetag(body, encoding)', function(){51 it('should support strings', function(){52 utils.wetag('express!')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 53why, one step back53 .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 54–57why, one step back54 })5556 it('should support utf8 strings', function(){57 utils.wetag('express❤', 'utf8')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 58why, one step back58 .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 59–61why, one step back59 })6061 it('should support buffer', function(){Use safe-buffer for improved Buffer APIDouglas Christopher Wilsonbefore adoption12c3712
line 62why, one step back62 utils.wetag(Buffer.from('express!'))deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 63why, one step back63 .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 64–67why, one step back64 })6566 it('should support empty string', function(){67 utils.wetag('')deps: etag@~1.8.0Douglas Christopher Wilsonbefore adoption9f4dbae
line 68why, one step back68 .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 69–95why, one step back69 })70})7172describe('utils.isAbsolute()', function(){73 it('should support windows', function(){74 assert(utils.isAbsolute('c:\\'));75 assert(utils.isAbsolute('c:/'));76 assert(!utils.isAbsolute(':\\'));77 })7879 it('should support windows unc', function(){80 assert(utils.isAbsolute('\\\\foo\\bar'))81 })8283 it('should support unices', function(){84 assert(utils.isAbsolute('/foo/bar'));85 assert(!utils.isAbsolute('foo/bar'));86 })87})8889describe('utils.flatten(arr)', function(){90 it('should flatten an array', function(){91 var arr = ['one', ['two', ['three', 'four'], 'five']];92 utils.flatten(arr)93 .should.eql(['one', 'two', 'three', 'four', 'five']);94 })95})