cleanup: remove unnecessary require for global Buffer
[express.git] / test / utils.js
blobae73988b01d092dd26dd266d77bafc3daff8b75e
1 'use strict'
3 var assert = require('assert');
4 var utils = require('../lib/utils');
6 describe('utils.etag(body, encoding)', function(){
7 it('should support strings', function(){
8 assert.strictEqual(utils.etag('express!'),
9 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
12 it('should support utf8 strings', function(){
13 assert.strictEqual(utils.etag('express❤', 'utf8'),
14 '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
17 it('should support buffer', function(){
18 assert.strictEqual(utils.etag(Buffer.from('express!')),
19 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
22 it('should support empty string', function(){
23 assert.strictEqual(utils.etag(''),
24 '"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);
31 });
33 it('should return type if not given charset', function () {
34 assert.strictEqual(utils.setCharset('text/html'), 'text/html');
35 });
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');
39 });
41 it('should set charset', function () {
42 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');
43 });
45 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 });
50 describe('utils.wetag(body, encoding)', function(){
51 it('should support strings', function(){
52 assert.strictEqual(utils.wetag('express!'),
53 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
56 it('should support utf8 strings', function(){
57 assert.strictEqual(utils.wetag('express❤', 'utf8'),
58 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
61 it('should support buffer', function(){
62 assert.strictEqual(utils.wetag(Buffer.from('express!')),
63 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
66 it('should support empty string', function(){
67 assert.strictEqual(utils.wetag(''),
68 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')