utils.js
This file
Path
test/utils.js
43 lines · 1.1 KiB · JavaScript
Last changed by
use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c
History of this fileTake it
The walk stopped after 200 commits: lines older than c1d16e0 point at it.
Release 3.3.7TJ Holowaychukbefore adoptionc1d16e0
lines 1–43why, 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>';910 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 })3031 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})