utils.js
This file
Path
test/utils.js
95 lines · 2.6 KiB · JavaScript
Last changed by
tests: add extra setCharset testsDouglas Christopher Wilsonbefore adoption53e5991
History of this fileTake it
The walk stopped after 200 commits: lines older than ad3ca25 point at it.
deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
line 1why, one step back1tests: add extra setCharset testsDouglas Christopher Wilsonbefore adoption53e5991
lines 2–3why, one step back2var assert = require('assert');3var utils = require('../lib/utils');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 4–26why, one step back45describe('utils.etag(body, encoding)', function(){6 it('should support strings', function(){7 utils.etag('express!')8 .should.eql('"zZdv4imtWD49AHEviejT6A=="')9 })1011 it('should support utf8 strings', function(){12 utils.etag('express❤', 'utf8')13 .should.eql('"fsFba4IxwQS6h6Umb+FNxw=="')14 })1516 it('should support buffer', function(){17 var buf = new Buffer('express!')18 utils.etag(buf)19 .should.eql('"zZdv4imtWD49AHEviejT6A=="');20 })2122 it('should support empty string', function(){23 utils.etag('')24 .should.eql('"1B2M2Y8AsgTpgAmY7PhCfg=="');25 })26})tests: add extra setCharset testsDouglas Christopher Wilsonbefore adoption53e5991
lines 27–48why, one step back2728describe('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});deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 49–52why, one step back4950describe('utils.wetag(body, encoding)', function(){51 it('should support strings', function(){52 utils.wetag('express!')Use etag to generate ETag headersDouglas Christopher Wilsonbefore adoption51d33ed
line 53why, one step back53 .should.eql('W/"8-b8aabac7"')deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 54–57why, one step back54 })5556 it('should support utf8 strings', function(){57 utils.wetag('express❤', 'utf8')Use etag to generate ETag headersDouglas Christopher Wilsonbefore adoption51d33ed
line 58why, one step back58 .should.eql('W/"a-686b0af1"')deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 59–63why, one step back59 })6061 it('should support buffer', function(){62 var buf = new Buffer('express!')63 utils.wetag(buf)Use etag to generate ETag headersDouglas Christopher Wilsonbefore adoption51d33ed
line 64why, one step back64 .should.eql('W/"8-b8aabac7"');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 65–95why, one step back65 })6667 it('should support empty string', function(){68 utils.wetag('')69 .should.eql('W/"0-0"');70 })71})7273describe('utils.isAbsolute()', function(){74 it('should support windows', function(){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})