2 var assert = require('assert');
3 var Buffer = require('safe-buffer').Buffer
4 var utils = require('../lib/utils');
6 describe('utils.etag(body, encoding)', function(){
7 it('should support strings', function(){
9 .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
12 it('should support utf8 strings', function(){
13 utils.etag('express❤', 'utf8')
14 .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
17 it('should support buffer', function(){
18 utils.etag(Buffer.from('express!'))
19 .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
22 it('should support empty string', function(){
24 .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
28 describe('utils.setCharset(type, charset)', function () {
29 it('should do anything without type', function () {
30 assert.strictEqual(utils.setCharset(), undefined);
33 it('should return type if not given charset', function () {
34 assert.strictEqual(utils.setCharset('text/html'), 'text/html');
37 it('should keep charset if not given charset', function () {
38 assert.strictEqual(utils.setCharset('text/html; charset=utf-8'), 'text/html; charset=utf-8');
41 it('should set charset', function () {
42 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');
45 it('should override charset', function () {
46 assert.strictEqual(utils.setCharset('text/html; charset=iso-8859-1', 'utf-8'), 'text/html; charset=utf-8');
50 describe('utils.wetag(body, encoding)', function(){
51 it('should support strings', function(){
52 utils.wetag('express!')
53 .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
56 it('should support utf8 strings', function(){
57 utils.wetag('express❤', 'utf8')
58 .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
61 it('should support buffer', function(){
62 utils.wetag(Buffer.from('express!'))
63 .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
66 it('should support empty string', function(){
68 .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
72 describe('utils.isAbsolute()', function(){
73 it('should support windows', function(){
74 assert(utils.isAbsolute('c:\\'));
75 assert(utils.isAbsolute('c:/'));
76 assert(!utils.isAbsolute(':\\'));
79 it('should support windows unc', function(){
80 assert(utils.isAbsolute('\\\\foo\\bar'))
83 it('should support unices', function(){
84 assert(utils.isAbsolute('/foo/bar'));
85 assert(!utils.isAbsolute('foo/bar'));
89 describe('utils.flatten(arr)', function(){
90 it('should flatten an array', function(){
91 var arr = ['one', ['two', ['three', 'four'], 'five']];
93 .should.eql(['one', 'two', 'three', 'four', 'five']);