utils.js
This file
Path
test/utils.js
50 lines · 1.3 KiB · JavaScript
Last changed by
refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
History of this fileTake it
The walk stopped after 200 commits: lines older than 14fcfde point at it.
update connectTJ Holowaychukbefore adoption14fcfde
lines 1–8why, one step back12var utils = require('../lib/utils')3 , assert = require('assert');45describe('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>';fix long list params testTJ Holowaychukbefore adoption99bc628
line 9why, one step back9update connectTJ Holowaychukbefore adoption14fcfde
lines 10–29why, one step back10 it('should support strings', function(){11 utils.etag(str).should.eql('"-2034458343"');12 })1314 it('should support utf8 strings', function(){15 utils.etag(strUTF8).should.eql('"1395090196"');16 })1718 it('should support buffer', function(){19 utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');20 utils.etag(new Buffer(str)).should.eql('"-2034458343"');21 })2223})2425describe('utils.isAbsolute()', function(){26 it('should support windows', function(){27 assert(utils.isAbsolute('c:\\'));28 assert(!utils.isAbsolute(':\\'));29 })fix long list params testTJ Holowaychukbefore adoption99bc628
line 30why, one step back30update connectTJ Holowaychukbefore adoption14fcfde
lines 31–50why, one step back31 it('should unices', function(){32 assert(utils.isAbsolute('/foo/bar'));33 assert(!utils.isAbsolute('foo/bar'));34 })35})3637describe('utils.flatten(arr)', function(){38 it('should flatten an array', function(){39 var arr = ['one', ['two', ['three', 'four'], 'five']];40 utils.flatten(arr)41 .should.eql(['one', 'two', 'three', 'four', 'five']);42 })43})4445describe('utils.escape(html)', function(){46 it('should escape html entities', function(){47 utils.escape('<script>foo & "bar"')48 .should.equal('<script>foo & "bar"')49 })50})